Skip to content

Commit

Permalink
fix(lints): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed Mar 29, 2024
1 parent 3aafb82 commit aee5ab9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 30 deletions.
5 changes: 1 addition & 4 deletions cmds/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ func newLintCmd() *cobra.Command {
return err
}

msgs, err := locallsp.GetDiagnostics(rootPath, chart.ValuesFiles.MainValuesFile.Values)
if err != nil {
return err
}
msgs := locallsp.GetDiagnostics(rootPath, chart.ValuesFiles.MainValuesFile.Values)

for _, msg := range msgs {
fmt.Println(msg)
Expand Down
16 changes: 7 additions & 9 deletions internal/adapter/yamlls/yamlls.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Connector struct {
client protocol.Client
}

func NewConnector(yamllsConfiguration util.YamllsConfiguration, client protocol.Client, documents *lsplocal.DocumentStore) *Connector {
func NewConnector(ctx context.Context, yamllsConfiguration util.YamllsConfiguration, client protocol.Client, documents *lsplocal.DocumentStore) *Connector {
yamllsCmd := exec.Command(yamllsConfiguration.Path, "--stdio")

stdin, err := yamllsCmd.StdinPipe()
Expand All @@ -43,12 +43,6 @@ func NewConnector(yamllsConfiguration util.YamllsConfiguration, client protocol.
return &Connector{}
}

go func() {
for {
io.Copy(os.Stderr, strderr)
}
}()

readWriteCloser := readWriteCloseSubprocess{
stout,
stdin,
Expand All @@ -68,11 +62,15 @@ func NewConnector(yamllsConfiguration util.YamllsConfiguration, client protocol.
return &Connector{}
}
}

go func() {
io.Copy(os.Stderr, strderr)

Check failure on line 67 in internal/adapter/yamlls/yamlls.go

View workflow job for this annotation

GitHub Actions / lint (1.21.5, ubuntu-latest)

Error return value of `io.Copy` is not checked (errcheck)
}()

yamllsConnector := Connector{documents: documents, config: yamllsConfiguration, client: client}

ctx := context.Background()
zapLogger, _ := zap.NewProduction()
ctx, _, server := protocol.NewClient(ctx, yamllsConnector, jsonrpc2.NewStream(readWriteCloser), zapLogger)
_, _, server := protocol.NewClient(ctx, yamllsConnector, jsonrpc2.NewStream(readWriteCloser), zapLogger)

yamllsConnector.server = server
return &yamllsConnector
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/initialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (h *langHandler) initializationWithConfig(ctx context.Context) {
func configureYamlls(ctx context.Context, h *langHandler) {
config := h.helmlsConfig
if config.YamllsConfiguration.Enabled {
h.yamllsConnector = yamlls.NewConnector(config.YamllsConfiguration, h.client, h.documents)
h.yamllsConnector = yamlls.NewConnector(ctx, config.YamllsConfiguration, h.client, h.documents)
err := h.yamllsConnector.CallInitialize(ctx, h.chartStore.RootURI)
if err != nil {
logger.Error("Error initializing yamlls", err)
Expand Down
11 changes: 4 additions & 7 deletions internal/handler/text_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ func (h *langHandler) DidOpen(ctx context.Context, params *lsp.DidOpenTextDocume
if err != nil {
logger.Error("Error getting chart info for file", doc.URI, err)
}
notification, err := lsplocal.NotificationFromLint(ctx, h.connPool, chart, doc)
notification := lsplocal.NotificationFromLint(ctx, h.connPool, chart, doc)

h.client.PublishDiagnostics(ctx, notification)

return err
return h.client.PublishDiagnostics(ctx, notification)
}

func (h *langHandler) DidClose(ctx context.Context, params *lsp.DidCloseTextDocumentParams) (err error) {
Expand All @@ -53,10 +51,9 @@ func (h *langHandler) DidSave(ctx context.Context, params *lsp.DidSaveTextDocume
}

h.yamllsConnector.DocumentDidSave(doc, *params)
notification, err := lsplocal.NotificationFromLint(ctx, h.connPool, chart, doc)
notification := lsplocal.NotificationFromLint(ctx, h.connPool, chart, doc)

h.client.PublishDiagnostics(ctx, notification)
return nil
return h.client.PublishDiagnostics(ctx, notification)
}

func (h *langHandler) DidChange(ctx context.Context, params *lsp.DidChangeTextDocumentParams) (err error) {
Expand Down
14 changes: 5 additions & 9 deletions internal/lsp/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,24 @@ import (

var logger = log.GetLogger()

func NotificationFromLint(ctx context.Context, conn jsonrpc2.Conn, chart *charts.Chart, doc *Document) (*lsp.PublishDiagnosticsParams, error) {
func NotificationFromLint(_ context.Context, conn jsonrpc2.Conn, chart *charts.Chart, doc *Document) *lsp.PublishDiagnosticsParams {

Check failure on line 26 in internal/lsp/lint.go

View workflow job for this annotation

GitHub Actions / lint (1.21.5, ubuntu-latest)

unused-parameter: parameter 'conn' seems to be unused, consider removing or renaming it as _ (revive)
vals := chart.ValuesFiles.MainValuesFile.Values
if chart.ValuesFiles.OverlayValuesFile != nil {
vals = chartutil.CoalesceTables(chart.ValuesFiles.OverlayValuesFile.Values, chart.ValuesFiles.MainValuesFile.Values)
}

diagnostics, err := GetDiagnostics(doc.URI, vals)
if err != nil {
return nil, err
}
diagnostics := GetDiagnostics(doc.URI, vals)
doc.DiagnosticsCache.HelmDiagnostics = diagnostics

return &lsp.PublishDiagnosticsParams{
URI: doc.URI,
Diagnostics: doc.DiagnosticsCache.GetMergedDiagnostics(),
}, nil
}
}

// GetDiagnostics will run helm linter against the currect document URI using the given values
// and converts the helm.support.Message to lsp.Diagnostics
func GetDiagnostics(uri uri.URI, vals chartutil.Values) ([]lsp.Diagnostic, error) {
func GetDiagnostics(uri uri.URI, vals chartutil.Values) []lsp.Diagnostic {
var (
filename = uri.Filename()
paths = strings.Split(filename, "/")
Expand All @@ -60,7 +57,6 @@ func GetDiagnostics(uri uri.URI, vals chartutil.Values) ([]lsp.Diagnostic, error
}
}

logger.Println(dir)
client := action.NewLint()

result := client.Run([]string{dir}, vals)
Expand All @@ -77,7 +73,7 @@ func GetDiagnostics(uri uri.URI, vals chartutil.Values) ([]lsp.Diagnostic, error
diagnostics = append(diagnostics, *d)
}

return diagnostics, nil
return diagnostics
}

func GetDiagnosticFromLinterErr(supMsg support.Message) (*lsp.Diagnostic, string, error) {
Expand Down

0 comments on commit aee5ab9

Please sign in to comment.