diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa2a65e0..a53eeb01 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,18 +28,18 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - uses: actions/setup-go@v5 with: go-version: "1.21" cache: false - name: golangci-lint - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v8 with: # Require: The version of golangci-lint to use. # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. - version: v1.64.4 + version: v2.3.1 check-license: name: License scan diff --git a/.golangci.yml b/.golangci.yml index 648cd5cb..8b9d40e8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,77 +1,81 @@ +version: "2" run: - # default concurrency is a available CPU number concurrency: 4 - - # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 5m - - # exit code when at least one issue was found, default is 1 issues-exit-code: 1 - - # include test files or not, default is true tests: true - -linters-settings: - depguard: - rules: - main: - list-mode: lax - allow: - - $gostd - - github.com/stackvista - lll: - line-length: 250 - mnd: - checks: - - argument - - case - - condition - - return - - nolintlint: - allow-unused: true # report any unused nolint directives - require-specific: true # don't require nolint directives to be specific about which linter is being skipped - - stylecheck: - - funlen: - lines: 100 - statements: 60 - linters: - disable-all: true + default: none enable: - # - bodyclose TODO: enable when fixed - # - depguard + - copyloopvar - dogsled - dupl - errcheck - exhaustive - - copyloopvar - funlen - gochecknoinits - goconst - gocritic - gocyclo - - gofmt - - goimports - - mnd - goprintffuncname - # - gosec TODO: enable when fixed - - gosimple - govet - ineffassign - lll - misspell + - mnd - nakedret - noctx - nolintlint - # - revive TODO: enable when fixed - rowserrcheck - staticcheck - # - stylecheck TODO: enable when fixed - - typecheck - unconvert - unparam - unused - whitespace + # - gosec TODO: enable when fixed + # - bodyclose TODO: enable when fixed + # - depguard + # - revive TODO: enable when fixed + # - stylecheck TODO: enable when fixed + settings: + depguard: + rules: + main: + list-mode: lax + allow: + - $gostd + - github.com/stackvista + funlen: + lines: 100 + statements: 60 + lll: + line-length: 250 + mnd: + checks: + - argument + - case + - condition + - return + nolintlint: + require-specific: true + allow-unused: true + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/cmd/dashboard/dashboard_edit_test.go b/cmd/dashboard/dashboard_edit_test.go index 1dedb7de..f5d78810 100644 --- a/cmd/dashboard/dashboard_edit_test.go +++ b/cmd/dashboard/dashboard_edit_test.go @@ -96,7 +96,7 @@ func TestShouldEditDashboard(t *testing.T) { "scope": "privateDashboard" }`), } - cli.Deps.Editor = mockEditor + cli.Editor = mockEditor di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--id", "1234") @@ -136,7 +136,7 @@ func TestShouldEditDashboardWithIdentifier(t *testing.T) { "description": "Updated via identifier" }`), } - cli.Deps.Editor = mockEditor + cli.Editor = mockEditor di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--identifier", "urn:custom:dashboard:edit-test") @@ -153,7 +153,7 @@ func TestEditDashboardNoChanges(t *testing.T) { // Custom editor that returns exactly the same content as input noChangeEditor := &NoChangeEditor{} - cli.Deps.Editor = noChangeEditor + cli.Editor = noChangeEditor di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--id", "1234") @@ -186,7 +186,7 @@ func TestEditDashboardWithJsonOutput(t *testing.T) { "description": "Testing JSON output" }`), } - cli.Deps.Editor = mockEditor + cli.Editor = mockEditor di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--id", "1234", "--output", "json") @@ -204,7 +204,7 @@ func TestEditDashboardNoChangesJsonOutput(t *testing.T) { // Use NoChangeEditor that returns exactly the same content noChangeEditor := &NoChangeEditor{} - cli.Deps.Editor = noChangeEditor + cli.Editor = noChangeEditor di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--id", "1234", "--output", "json") @@ -223,7 +223,7 @@ func TestEditDashboardInvalidJson(t *testing.T) { mockEditor := &MockEditor{ Content: []byte(`{"invalid": json syntax}`), } - cli.Deps.Editor = mockEditor + cli.Editor = mockEditor _, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--id", "1234") @@ -242,7 +242,7 @@ func TestEditDashboardEditorError(t *testing.T) { mockEditor := &MockEditor{ Error: errors.New("editor failed to open"), } - cli.Deps.Editor = mockEditor + cli.Editor = mockEditor _, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--id", "1234") @@ -275,7 +275,7 @@ func TestEditDashboardUsesReverseEditorByDefault(t *testing.T) { mockEditor := &MockEditor{ Content: []byte(`{"name": "changed-by-reverse-editor"}`), } - cli.Deps.Editor = mockEditor + cli.Editor = mockEditor di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--id", "1234") @@ -324,7 +324,7 @@ func TestEditDashboardApiErrors(t *testing.T) { mockEditor := &MockEditor{ Content: []byte(`{"name": "changed"}`), } - cli.Deps.Editor = mockEditor + cli.Editor = mockEditor } _, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--id", "1234") diff --git a/cmd/stackpack/stackpack_describe.go b/cmd/stackpack/stackpack_describe.go index 6707eb7c..8cd7a328 100644 --- a/cmd/stackpack/stackpack_describe.go +++ b/cmd/stackpack/stackpack_describe.go @@ -85,6 +85,7 @@ func RunStackpackDescribeCommand(args *DescribeArgs) di.CmdWithApiFn { } } + //nolint:staticcheck notFound := fmt.Errorf("StackPack '%s' not found.", args.Name) if cli.IsJson() { cli.Printer.PrintErrJson(notFound) diff --git a/cmd/stackpack/stackpack_test_cmd_test.go b/cmd/stackpack/stackpack_test_cmd_test.go index da1a54f1..f3da3ddb 100644 --- a/cmd/stackpack/stackpack_test_cmd_test.go +++ b/cmd/stackpack/stackpack_test_cmd_test.go @@ -437,6 +437,7 @@ func TestConfirmUpload(t *testing.T) { // In a real test environment, you'd mock the stdin reader // Just verify the function signature is correct + //nolint:staticcheck var confirmFunc func(*di.Deps, string) bool = confirmUpload assert.NotNil(t, confirmFunc) diff --git a/cmd/stackpack/test-stackpack-1.0.0-cli-test.10000.zip b/cmd/stackpack/test-stackpack-1.0.0-cli-test.10000.zip new file mode 100644 index 00000000..bab9cd21 Binary files /dev/null and b/cmd/stackpack/test-stackpack-1.0.0-cli-test.10000.zip differ diff --git a/internal/client/stackstate_version.go b/internal/client/stackstate_version.go index 9c012c35..0e317d67 100644 --- a/internal/client/stackstate_version.go +++ b/internal/client/stackstate_version.go @@ -63,5 +63,5 @@ func CheckVersionCompatibility(version stackstate_api.ServerVersion, minVersion } func NewAPIVersionMismatchError(got string, expected string) common.CLIError { - return common.NewAPIVersionError(fmt.Errorf("Incompatible API version: got '%s', but need '%s'-compatible version", got, expected)) + return common.NewAPIVersionError(fmt.Errorf("incompatible API version: got '%s', but need '%s'-compatible version", got, expected)) } diff --git a/internal/config/config.go b/internal/config/config.go index cc257349..db252484 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -81,7 +81,7 @@ func (c *Config) GetContext(name string) (*NamedContext, common.CLIError) { } } - return nil, common.NewNotFoundError(fmt.Errorf("Context with name '%s' not found", name)) + return nil, common.NewNotFoundError(fmt.Errorf("context with name '%s' not found", name)) } // UnmarshalYAML unmarshals the StsContext YAML part into a struct, ensuring that any defaults are set. @@ -153,7 +153,7 @@ func (c *StsContext) Validate(contextName string) common.CLIError { authenticationTokens := util.RemoveEmpty([]string{c.APIToken, c.ServiceToken, c.K8sSAToken}) if len(authenticationTokens) > 1 { - errors = append(errors, fmt.Errorf("Can only specify one of {api-token | service-token | k8s-sa-token}")) + errors = append(errors, fmt.Errorf("can only specify one of {api-token | service-token | k8s-sa-token}")) } if c.HasCaCertificateFromArgSet() { diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 97ae66bc..0d537844 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -181,7 +181,7 @@ current-context: default assert.NoError(t, err) assert.ErrorContains(t, c.Contexts[0].Context.Validate(c.Contexts[0].Name), `Failed to validate the 'default' context: * URL localhost:8080 must start with "https://" or "http://" -* Can only specify one of {api-token | service-token | k8s-sa-token}`) +* can only specify one of {api-token | service-token | k8s-sa-token}`) } func TestMergeWithNoTokenOverride(t *testing.T) { diff --git a/main_test.go b/main_test.go index 091b2cc6..745305d9 100644 --- a/main_test.go +++ b/main_test.go @@ -190,7 +190,7 @@ func TestExitCodeOnError(t *testing.T) { main() return } - cmd := exec.Command(os.Args[0], "-test.run=TestExitCodeOnError") //nolint:gosec + cmd := exec.Command(os.Args[0], "-test.run=TestExitCodeOnError") //nolint:gosec,noctx cmd.Env = append(os.Environ(), "BE_CRASHER=1") err := cmd.Run() if e, ok := err.(*exec.ExitError); ok && !e.Success() { diff --git a/pkg/pflags/relative_time_flag.go b/pkg/pflags/relative_time_flag.go index ab17d0c0..16df13b1 100644 --- a/pkg/pflags/relative_time_flag.go +++ b/pkg/pflags/relative_time_flag.go @@ -116,7 +116,7 @@ func (d *RelativeTimeValue) Type() string { return RelativeTimeFlagType } -func (d *RelativeTimeValue) String() string { return d.Time.Format(time.RFC3339Nano) } +func (d *RelativeTimeValue) String() string { return d.Format(time.RFC3339Nano) } // GetRelativeTime return the time value of a flag with the given name func GetRelativeTime(f *pflag.FlagSet, name string) (time.Time, error) {