From 54047c1ac631719bbd2abdd8aed37f3368bf389b Mon Sep 17 00:00:00 2001 From: Alessio Biancalana Date: Wed, 10 Sep 2025 14:30:39 +0200 Subject: [PATCH 1/5] STAC-0: upgrade golangcilint config to v2 --- .golangci.yml | 100 ++++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 48 deletions(-) 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$ From d0004fb58019cddfe932a9773059dc4aa70dc101 Mon Sep 17 00:00:00 2001 From: Alessio Biancalana Date: Wed, 10 Sep 2025 15:29:01 +0200 Subject: [PATCH 2/5] STAC-0: fix fresh linting issues --- cmd/dashboard/dashboard_edit_test.go | 16 +++++++++------- cmd/stackpack/stackpack_describe.go | 1 + cmd/stackpack/stackpack_test_cmd_test.go | 1 + internal/client/stackstate_version.go | 2 +- internal/config/config.go | 4 ++-- internal/config/config_test.go | 2 +- pkg/pflags/relative_time_flag.go | 2 +- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cmd/dashboard/dashboard_edit_test.go b/cmd/dashboard/dashboard_edit_test.go index 1dedb7de..d6eb5b2c 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,6 +223,7 @@ func TestEditDashboardInvalidJson(t *testing.T) { mockEditor := &MockEditor{ Content: []byte(`{"invalid": json syntax}`), } + //nolint:staticcheck cli.Deps.Editor = mockEditor _, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--id", "1234") @@ -242,6 +243,7 @@ func TestEditDashboardEditorError(t *testing.T) { mockEditor := &MockEditor{ Error: errors.New("editor failed to open"), } + //nolint:staticcheck cli.Deps.Editor = mockEditor _, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--id", "1234") @@ -275,7 +277,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 +326,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/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/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) { From 01d237bf09694fc7bf713821781a7e424fdf8cf2 Mon Sep 17 00:00:00 2001 From: Alessio Biancalana Date: Wed, 10 Sep 2025 15:47:12 +0200 Subject: [PATCH 3/5] STAC-0: migrate to golangcilint v2 in CI too --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 From 7aad0c8869e3456543ca584f0fb0786cb3346984 Mon Sep 17 00:00:00 2001 From: Alessio Biancalana Date: Wed, 10 Sep 2025 15:51:46 +0200 Subject: [PATCH 4/5] STAC-0: ignore a noctx linting issue in main_test.go --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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() { From 9520ce0a22ab6e7125b58e2849e50f97aafea73b Mon Sep 17 00:00:00 2001 From: Alessio Biancalana Date: Wed, 10 Sep 2025 17:44:10 +0200 Subject: [PATCH 5/5] STAC-0: remove a couple more nolint statements --- cmd/dashboard/dashboard_edit_test.go | 6 ++---- .../test-stackpack-1.0.0-cli-test.10000.zip | Bin 0 -> 758 bytes 2 files changed, 2 insertions(+), 4 deletions(-) create mode 100644 cmd/stackpack/test-stackpack-1.0.0-cli-test.10000.zip diff --git a/cmd/dashboard/dashboard_edit_test.go b/cmd/dashboard/dashboard_edit_test.go index d6eb5b2c..f5d78810 100644 --- a/cmd/dashboard/dashboard_edit_test.go +++ b/cmd/dashboard/dashboard_edit_test.go @@ -223,8 +223,7 @@ func TestEditDashboardInvalidJson(t *testing.T) { mockEditor := &MockEditor{ Content: []byte(`{"invalid": json syntax}`), } - //nolint:staticcheck - cli.Deps.Editor = mockEditor + cli.Editor = mockEditor _, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--id", "1234") @@ -243,8 +242,7 @@ func TestEditDashboardEditorError(t *testing.T) { mockEditor := &MockEditor{ Error: errors.New("editor failed to open"), } - //nolint:staticcheck - cli.Deps.Editor = mockEditor + cli.Editor = mockEditor _, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--id", "1234") 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 0000000000000000000000000000000000000000..bab9cd21b78e73a739eb7d2f586bea96cbf7b688 GIT binary patch literal 758 zcmWIWW@Zs#-~d8&APN*HD9SI(EY8f&%gjsHFG(#f(JL;g)biBT3)Ij!rGHxI+?n&I z&v>)5Ffjc8AK=Z-@t!xQQXHsH5QqbCn#>854RUpK@paY9O$iFq0GfAESI^VuoSuiz zxo3~KPM**S10oNW(;5d-zc4VuOy9GmW0^WouQp!OLGCU}EzU13N=_}-&o4_YD$7hQ z2igR7_X&M(U9HnTx(GMFytXS=7^sIAuc>@M+2WGK_<)=SRMOH1kB+jZE1r{#Ao z*T!|_6W5oQZ?)VpAx^_6?vJ+$Pv!3oH~(1d5V~}xCP^#cUFxFEF{Zl4Ee!wNY}OoM zexWsI*O8RSTV1NV-n%gWQ(sgrdd9?)ZA+z|Y=l1RH+LJC?-QgysAW0E`xkwfR3iKG zn%(F9sk(cV)8FSEnD4^dcP2O7Lv5Ds$KPcsdGn1*k90I17cnxq*3ohAE;B5+_T5;# zd@j)08o&Sy@MdHZVL(JQazudw3>9FFc61|