Skip to content

Commit 0c956c5

Browse files
fix: golangci config, linter errors (#704)
1 parent 68655f0 commit 0c956c5

File tree

84 files changed

+373
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+373
-370
lines changed

.golangci.yaml

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ run:
33
- integration
44
concurrency: 4
55
issues-exit-code: 1
6-
skip-dirs:
7-
- "docs"
8-
- "licenses"
9-
- "pact"
10-
- "ampli"
11-
- ".bin"
12-
- ".github"
13-
- ".vscode"
14-
- "build"
156
tests: true
167
timeout: 5m
178

@@ -40,7 +31,6 @@ linters-settings:
4031
gosimple:
4132
checks: ['all']
4233
govet:
43-
check-shadowing: true
4434
enable-all: true
4535
disable:
4636
- fieldalignment
@@ -69,7 +59,6 @@ linters-settings:
6959
- name: error-strings
7060
- name: error-naming
7161
- name: exported
72-
disable-stuttering-check: true
7362
- name: if-return
7463
- name: increment-decrement
7564
- name: var-naming
@@ -92,8 +81,6 @@ linters-settings:
9281
stylecheck:
9382
checks: ['all']
9483
http-status-code-whitelist: []
95-
varcheck:
96-
exported-fields: true
9784

9885
linters:
9986
enable:
@@ -109,14 +96,11 @@ linters:
10996
- dupl
11097
- durationcheck
11198
- errname
112-
# TODO(errorlint): revisit
113-
#- errorlint
99+
- errorlint
114100
- exhaustive
115-
- exportloopref
116-
# TODO(forbidigo): revisit
117-
#- forbidigo
118-
# TODO(forcetypeassert): revisit this one! beware fragile asserts in this codebase
119-
#- forcetypeassert
101+
- copyloopvar
102+
- forbidigo
103+
- forcetypeassert
120104
# TODO(goconst): revisit
121105
#- goconst
122106
# TODO(gocritic): revisit
@@ -127,7 +111,7 @@ linters:
127111
# TODO(gofumpt): revisit
128112
#- gofumpt
129113
# TODO(goimports): revisit
130-
#- goimports
114+
- goimports
131115
- goprintffuncname
132116
# TODO(gosec): revisit; consequences of revoking non-owner file permissions?
133117
#- gosec
@@ -153,7 +137,7 @@ linters:
153137
- predeclared
154138
- promlinter
155139
# TODO(revive): revisit in a followup; extensive changes, some breaking. godoc requirement would be good to introduce
156-
#- revive
140+
# - revive
157141
- rowserrcheck
158142
- sqlclosecheck
159143
# TODO(stylecheck): revisit in a followup; some breaking API changes
@@ -174,6 +158,16 @@ linters:
174158
#- wrapcheck
175159

176160
issues:
161+
exclude-dirs:
162+
- "docs"
163+
- "licenses"
164+
- "pact"
165+
- "ampli"
166+
- ".bin"
167+
- ".github"
168+
- ".vscode"
169+
- "build"
170+
177171
exclude-rules:
178172
- path: _test\.go
179173
linters:

application/codeaction/codeaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (c *CodeActionsService) getQuickFixAction(quickFixGroupables []types.Groupa
120120
// right now we can always group by max semver version, as
121121
// code only has one quickfix available, and iac none at all
122122
var quickFix *snyk.CodeAction
123-
qf, ok := types.MaxSemver()(quickFixGroupables).(snyk.CodeAction)
123+
qf, ok := types.MaxSemver(c.logger)(quickFixGroupables).(snyk.CodeAction)
124124
if !ok {
125125
c.logger.Warn().Msg("grouping quick fix actions failed")
126126
quickFix = nil

application/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
frameworkLogging "github.com/snyk/go-application-framework/pkg/logging"
4646
"github.com/snyk/go-application-framework/pkg/runtimeinfo"
4747
"github.com/snyk/go-application-framework/pkg/workflow"
48+
4849
"github.com/snyk/snyk-ls/infrastructure/cli/cli_constants"
4950
"github.com/snyk/snyk-ls/infrastructure/cli/filename"
5051
"github.com/snyk/snyk-ls/internal/concurrency"

application/di/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
codeClient "github.com/snyk/code-client-go"
3131
codeClientHTTP "github.com/snyk/code-client-go/http"
3232
codeClientObservability "github.com/snyk/code-client-go/observability"
33+
3334
"github.com/snyk/snyk-ls/application/codeaction"
3435
"github.com/snyk/snyk-ls/application/config"
3536
appNotification "github.com/snyk/snyk-ls/application/server/notification"

application/entrypoint/helpers.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
func OnPanicRecover() {
1414
if err := recover(); err != nil {
1515
panickingMsg := "🚨 Panicking 🚨"
16-
fmt.Println(panickingMsg)
17-
fmt.Println(err)
16+
_, _ = fmt.Fprintln(os.Stderr, panickingMsg)
17+
_, _ = fmt.Fprintln(os.Stderr, err)
1818
debug.PrintStack()
1919

2020
c := config.CurrentConfig()
@@ -31,10 +31,9 @@ func OnPanicRecover() {
3131
}
3232

3333
func PrintLicenseText(output string) {
34-
fmt.Fprintln(os.Stderr, "License information")
35-
fmt.Fprintln(os.Stderr, "Snyk Language Server is licensed under the Apache 2.0 license")
36-
fmt.Fprintln(os.Stderr, "The following dependencies and licenses are used in this project:")
37-
fmt.Fprintln(os.Stderr, strings.ReplaceAll(output, " ", "\n"))
38-
fmt.Fprintln(os.Stderr,
39-
"You can access the detailed license information under https://github.com/snyk/snyk-ls/tree/main/licenses")
34+
_, _ = fmt.Fprintln(os.Stderr, "License information")
35+
_, _ = fmt.Fprintln(os.Stderr, "Snyk Language Server is licensed under the Apache 2.0 license")
36+
_, _ = fmt.Fprintln(os.Stderr, "The following dependencies and licenses are used in this project:")
37+
_, _ = fmt.Fprintln(os.Stderr, strings.ReplaceAll(output, " ", "\n"))
38+
_, _ = fmt.Fprintln(os.Stderr, "You can access the detailed license information under https://github.com/snyk/snyk-ls/tree/main/licenses")
4039
}

application/server/configuration.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/creachadair/jrpc2/handler"
3030

3131
"github.com/snyk/go-application-framework/pkg/configuration"
32+
3233
"github.com/snyk/snyk-ls/application/config"
3334
"github.com/snyk/snyk-ls/application/di"
3435
"github.com/snyk/snyk-ls/domain/ide/workspace"

application/server/configuration_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package server
1818

1919
import (
2020
"context"
21-
"fmt"
2221
"os"
2322
"path/filepath"
2423
"strconv"
@@ -33,6 +32,7 @@ import (
3332
"github.com/stretchr/testify/assert"
3433

3534
"github.com/snyk/go-application-framework/pkg/configuration"
35+
3636
"github.com/snyk/snyk-ls/internal/types"
3737

3838
"github.com/snyk/snyk-ls/application/config"
@@ -59,7 +59,6 @@ var sampleSettings = types.Settings{
5959
func keyFoundInEnv(key string) bool {
6060
found := false
6161
env := os.Environ()
62-
fmt.Println(env)
6362
for _, v := range env {
6463
if strings.HasPrefix(v, key+"=") {
6564
found = true

application/server/execute_command_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ package server
1818

1919
import (
2020
"context"
21-
"github.com/snyk/snyk-ls/domain/snyk"
22-
"github.com/snyk/snyk-ls/domain/snyk/scanner"
2321
"testing"
2422
"time"
2523

24+
"github.com/snyk/snyk-ls/domain/snyk"
25+
"github.com/snyk/snyk-ls/domain/snyk/scanner"
26+
2627
"github.com/sourcegraph/go-lsp"
2728
"github.com/stretchr/testify/assert"
2829

@@ -38,33 +39,33 @@ func Test_executeWorkspaceScanCommand_shouldStartWorkspaceScanOnCommandReceipt(t
3839
loc, _ := setupServerWithCustomDI(t, false)
3940
c := config.CurrentConfig()
4041

41-
scanner := &scanner.TestScanner{}
42-
workspace.Get().AddFolder(workspace.NewFolder(c, "dummy", "dummy", scanner, di.HoverService(), di.ScanNotifier(), di.Notifier(), di.ScanPersister()))
42+
s := &scanner.TestScanner{}
43+
workspace.Get().AddFolder(workspace.NewFolder(c, "dummy", "dummy", s, di.HoverService(), di.ScanNotifier(), di.Notifier(), di.ScanPersister()))
4344

4445
params := lsp.ExecuteCommandParams{Command: types.WorkspaceScanCommand}
4546
_, err := loc.Client.Call(ctx, "workspace/executeCommand", params)
4647
if err != nil {
4748
t.Fatal(err)
4849
}
4950
assert.Eventually(t, func() bool {
50-
return scanner.Calls() > 0
51+
return s.Calls() > 0
5152
}, 2*time.Second, time.Millisecond)
5253
}
5354

5455
func Test_executeWorkspaceFolderScanCommand_shouldStartFolderScanOnCommandReceipt(t *testing.T) {
5556
loc, _ := setupServerWithCustomDI(t, false)
5657
c := config.CurrentConfig()
5758

58-
scanner := &scanner.TestScanner{}
59-
workspace.Get().AddFolder(workspace.NewFolder(c, "dummy", "dummy", scanner, di.HoverService(), di.ScanNotifier(), di.Notifier(), di.ScanPersister()))
59+
s := &scanner.TestScanner{}
60+
workspace.Get().AddFolder(workspace.NewFolder(c, "dummy", "dummy", s, di.HoverService(), di.ScanNotifier(), di.Notifier(), di.ScanPersister()))
6061

6162
params := lsp.ExecuteCommandParams{Command: types.WorkspaceFolderScanCommand, Arguments: []any{"dummy"}}
6263
_, err := loc.Client.Call(ctx, "workspace/executeCommand", params)
6364
if err != nil {
6465
t.Fatal(err)
6566
}
6667
assert.Eventually(t, func() bool {
67-
return scanner.Calls() > 0
68+
return s.Calls() > 0
6869
}, 2*time.Second, time.Millisecond)
6970
}
7071

@@ -105,8 +106,8 @@ func Test_executeWorkspaceScanCommand_shouldAskForTrust(t *testing.T) {
105106
loc, jsonRPCRecorder := setupServerWithCustomDI(t, false)
106107
c := config.CurrentConfig()
107108

108-
scanner := &scanner.TestScanner{}
109-
workspace.Get().AddFolder(workspace.NewFolder(c, "dummy", "dummy", scanner, di.HoverService(), di.ScanNotifier(), di.Notifier(), di.ScanPersister()))
109+
s := &scanner.TestScanner{}
110+
workspace.Get().AddFolder(workspace.NewFolder(c, "dummy", "dummy", s, di.HoverService(), di.ScanNotifier(), di.Notifier(), di.ScanPersister()))
110111
// explicitly enable folder trust which is disabled by default in tests
111112
config.CurrentConfig().SetTrustedFolderFeatureEnabled(true)
112113

@@ -116,7 +117,7 @@ func Test_executeWorkspaceScanCommand_shouldAskForTrust(t *testing.T) {
116117
t.Fatal(err)
117118
}
118119
assert.Eventually(t, func() bool {
119-
return scanner.Calls() == 0 && checkTrustMessageRequest(jsonRPCRecorder)
120+
return s.Calls() == 0 && checkTrustMessageRequest(jsonRPCRecorder)
120121
}, 2*time.Second, time.Millisecond)
121122
}
122123

application/server/notification/scan_notifier_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
package notification_test
1818

1919
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
2024
notification2 "github.com/snyk/snyk-ls/application/server/notification"
2125
"github.com/snyk/snyk-ls/domain/snyk/scanner"
2226
"github.com/snyk/snyk-ls/internal/notification"
2327
"github.com/snyk/snyk-ls/internal/product"
2428
"github.com/snyk/snyk-ls/internal/testutil"
2529
"github.com/snyk/snyk-ls/internal/types"
26-
"github.com/stretchr/testify/assert"
27-
"testing"
2830
)
2931

3032
type sendMessageTestCase struct {

application/server/server_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package server
1818

1919
import (
2020
"context"
21-
"fmt"
2221
"os"
2322
"os/exec"
2423
"path/filepath"
@@ -156,14 +155,6 @@ func startServer(callBackFn onCallbackFn, jsonRPCRecorder *testutil.JsonRPCRecor
156155
return loc
157156
}
158157

159-
func Test_serverShouldStart(t *testing.T) {
160-
loc, _ := setupServer(t)
161-
162-
si := loc.Server.ServerInfo()
163-
164-
fmt.Println(strings.Join(si.Methods, "\n"))
165-
}
166-
167158
func Test_dummy_shouldNotBeServed(t *testing.T) {
168159
loc, _ := setupServer(t)
169160

0 commit comments

Comments
 (0)