diff --git a/.github/workflows/pr-linter-check.yml b/.github/workflows/pr-linter-check.yml index f2dc7c6e6c..36badcaa14 100644 --- a/.github/workflows/pr-linter-check.yml +++ b/.github/workflows/pr-linter-check.yml @@ -7,8 +7,16 @@ jobs: runs-on: ubuntu-latest steps: + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22' + - name: Check out the code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Linter check - run: make lint + - name: golangci-lint + uses: golangci/golangci-lint-action@v4 + with: + version: v1.57.2 + args: --out-format=colored-line-number diff --git a/golangci.yaml b/.golangci.yaml similarity index 98% rename from golangci.yaml rename to .golangci.yaml index c96c7428e0..cecb537c1c 100644 --- a/golangci.yaml +++ b/.golangci.yaml @@ -12,15 +12,6 @@ run: # exit code when at least one issue was found, default is 1 issues-exit-code: 1 - # which dirs to skip: issues from them won't be reported; - # can use regexp here: generated.*, regexp is applied on full path; - # default value is empty list, but default dirs are skipped independently - # from this option's value (see skip-dirs-use-default). - # "/" will be replaced by current OS file path separator to properly work - # on Windows. - skip-dirs: - - pkg/plugin/generated/* - # default is true. Enables skipping of directories: # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ skip-dirs-use-default: true @@ -44,7 +35,7 @@ run: # output configuration options output: # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" - format: colored-line-number + formats: colored-line-number # print lines of code with issue, default is true print-issued-lines: true @@ -148,10 +139,8 @@ linters-settings: # minimal confidence for issues, default is 0.8 min-confidence: 0.8 gomnd: - settings: - mnd: - # the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description. - checks: argument,case,condition,operation,return,assign + # the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description. + checks: argument,case,condition,operation,return,assign gomodguard: allowed: modules: # List of allowed modules @@ -389,6 +378,15 @@ issues: # Show only new issues created after git revision `REV` # new-from-rev: origin/main + # which dirs to skip: issues from them won't be reported; + # can use regexp here: generated.*, regexp is applied on full path; + # default value is empty list, but default dirs are skipped independently + # from this option's value (see skip-dirs-use-default). + # "/" will be replaced by current OS file path separator to properly work + # on Windows. + skip-dirs: + - pkg/plugin/generated/* + severity: # Default value is empty string. # Set the default severity for issues. If severity rules are defined and the issues diff --git a/hack/build-image/Dockerfile b/hack/build-image/Dockerfile index 161a837f0b..e2d966f73a 100644 --- a/hack/build-image/Dockerfile +++ b/hack/build-image/Dockerfile @@ -93,7 +93,7 @@ RUN ARCH=$(go env GOARCH) && \ chmod +x /usr/bin/goreleaser # get golangci-lint -RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.0 +RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.57.2 # install kubectl RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/$(go env GOARCH)/kubectl diff --git a/hack/lint.sh b/hack/lint.sh index 13ed64caba..737a6d6750 100755 --- a/hack/lint.sh +++ b/hack/lint.sh @@ -14,14 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -HACK_DIR=$(dirname "${BASH_SOURCE[0]}") - # Printing out cache status golangci-lint cache status # Enable GL_DEBUG line below for debug messages for golangci-lint # export GL_DEBUG=loader,gocritic,env -CMD="golangci-lint run -c $HACK_DIR/../golangci.yaml" +CMD="golangci-lint run" echo "Running $CMD" eval $CMD diff --git a/internal/hook/item_hook_handler_test.go b/internal/hook/item_hook_handler_test.go index f60110a5de..fccd511db6 100644 --- a/internal/hook/item_hook_handler_test.go +++ b/internal/hook/item_hook_handler_test.go @@ -1976,7 +1976,7 @@ func TestValidateContainer(t *testing.T) { expectedError := fmt.Errorf("invalid InitContainer in restore hook, it doesn't have Command, Name or Image field") // valid string should return nil as result. - assert.Equal(t, nil, ValidateContainer([]byte(valid))) + assert.Nil(t, ValidateContainer([]byte(valid))) // noName string should return expected error as result. assert.Equal(t, expectedError, ValidateContainer([]byte(noName))) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index c09d90ba6f..e54e72b61c 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -79,7 +79,7 @@ func TestConfig(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { client, err := Config(test.kubeconfig, test.kubecontext, "velero", test.QPS, test.burst) - assert.Equal(t, err, nil) + assert.NoError(t, err) assert.Equal(t, test.expectedHost, client.Host) assert.Equal(t, test.QPS, client.QPS) assert.Equal(t, test.burst, client.Burst) diff --git a/pkg/client/config_test.go b/pkg/client/config_test.go index b8e593d216..126262fbda 100644 --- a/pkg/client/config_test.go +++ b/pkg/client/config_test.go @@ -62,13 +62,13 @@ func TestConfigOperations(t *testing.T) { // Remove config file if it exists err := removeConfigfileName() - assert.Equal(t, err, nil) + assert.NoError(t, err) // Test LoadConfig: expect an empty velero config expectedConfig := VeleroConfig{} config, err := LoadConfig() - assert.Equal(t, err, nil) + assert.NoError(t, err) assert.True(t, reflect.DeepEqual(expectedConfig, config)) // Test savedConfig @@ -84,9 +84,9 @@ func TestConfigOperations(t *testing.T) { err = SaveConfig(config) - assert.Equal(t, err, nil) + assert.NoError(t, err) savedConfig, err := LoadConfig() - assert.Equal(t, err, nil) + assert.NoError(t, err) // Test Features feature := savedConfig.Features() @@ -107,7 +107,7 @@ func TestConfigOperations(t *testing.T) { t.Cleanup(func() { err = removeConfigfileName() - assert.Equal(t, err, nil) + assert.NoError(t, err) os.Unsetenv("HOME") os.Setenv("HOME", preHomeEnv) }) diff --git a/pkg/client/factory_test.go b/pkg/client/factory_test.go index 17569f1c85..3ab61c3230 100644 --- a/pkg/client/factory_test.go +++ b/pkg/client/factory_test.go @@ -95,7 +95,7 @@ func TestFactory(t *testing.T) { baseName := "velero-bn" config, err := LoadConfig() - assert.Equal(t, err, nil) + assert.NoError(t, err) for _, test := range tests { t.Run(test.name, func(t *testing.T) { f = NewFactory(baseName, config) diff --git a/pkg/cmd/cli/backup/delete_test.go b/pkg/cmd/cli/backup/delete_test.go index 0d34bc5a10..420523dd37 100644 --- a/pkg/cmd/cli/backup/delete_test.go +++ b/pkg/cmd/cli/backup/delete_test.go @@ -62,15 +62,15 @@ func TestDeleteCommand(t *testing.T) { args := []string{backup1, backup2} e := o.Complete(f, args) - require.Equal(t, nil, e) + require.NoError(t, e) e = o.Validate(c, f, args) - require.Equal(t, nil, e) + require.NoError(t, e) Run(o) e = c.Execute() - require.Equal(t, nil, e) + require.NoError(t, e) if os.Getenv(cmdtest.CaptureFlag) == "1" { return diff --git a/pkg/cmd/cli/backuplocation/create_test.go b/pkg/cmd/cli/backuplocation/create_test.go index dc2cb1aae0..5d838b66c1 100644 --- a/pkg/cmd/cli/backuplocation/create_test.go +++ b/pkg/cmd/cli/backuplocation/create_test.go @@ -148,7 +148,7 @@ func TestCreateCommand_Run(t *testing.T) { o.Complete(args, f) e := o.Validate(c, args, f) - assert.Equal(t, e, nil) + assert.NoError(t, e) e = o.Run(c, f) assert.Contains(t, e.Error(), fmt.Sprintf("%s: no such file or directory", caCertFile)) diff --git a/pkg/cmd/cli/backuplocation/set_test.go b/pkg/cmd/cli/backuplocation/set_test.go index cac77d1292..29b3299f5e 100644 --- a/pkg/cmd/cli/backuplocation/set_test.go +++ b/pkg/cmd/cli/backuplocation/set_test.go @@ -66,7 +66,7 @@ func TestNewSetCommand(t *testing.T) { args := []string{backupName} o.Complete(args, f) e := o.Validate(c, args, f) - assert.Equal(t, e, nil) + assert.NoError(t, e) e = o.Run(c, f) assert.Contains(t, e.Error(), fmt.Sprintf("%s: no such file or directory", cacert)) diff --git a/pkg/cmd/cli/restore/delete_test.go b/pkg/cmd/cli/restore/delete_test.go index b504e2c005..187aad39d0 100644 --- a/pkg/cmd/cli/restore/delete_test.go +++ b/pkg/cmd/cli/restore/delete_test.go @@ -62,15 +62,15 @@ func TestDeleteCommand(t *testing.T) { args := []string{restore1, restore2} e := o.Complete(f, args) - require.Equal(t, nil, e) + require.NoError(t, e) e = o.Validate(c, f, args) - require.Equal(t, nil, e) + require.NoError(t, e) Run(o) e = c.Execute() - require.Equal(t, nil, e) + require.NoError(t, e) if os.Getenv(cmdtest.CaptureFlag) == "1" { return diff --git a/pkg/datapath/file_system_test.go b/pkg/datapath/file_system_test.go index e39f73fdcd..8e496f1c04 100644 --- a/pkg/datapath/file_system_test.go +++ b/pkg/datapath/file_system_test.go @@ -101,7 +101,7 @@ func TestAsyncBackup(t *testing.T) { fs.callbacks = test.callbacks err := fs.StartBackup(AccessPoint{ByPath: test.path}, "", "", false, nil, map[string]string{}) - require.Equal(t, nil, err) + require.NoError(t, err) <-finish @@ -184,7 +184,7 @@ func TestAsyncRestore(t *testing.T) { fs.callbacks = test.callbacks err := fs.StartRestore(test.snapshot, AccessPoint{ByPath: test.path}, map[string]string{}) - require.Equal(t, nil, err) + require.NoError(t, err) <-finish diff --git a/pkg/datapath/manager_test.go b/pkg/datapath/manager_test.go index ebe18d1a03..fda574400e 100644 --- a/pkg/datapath/manager_test.go +++ b/pkg/datapath/manager_test.go @@ -36,7 +36,7 @@ func TestManager(t *testing.T) { assert.Equal(t, ConcurrentLimitExceed, err) ret := m.GetAsyncBR("job-0") - assert.Equal(t, nil, ret) + assert.Nil(t, ret) ret = m.GetAsyncBR("job-1") assert.Equal(t, async_job_1, ret) @@ -48,5 +48,5 @@ func TestManager(t *testing.T) { assert.Len(t, m.tracker, 1) ret = m.GetAsyncBR("job-1") - assert.Equal(t, nil, ret) + assert.Nil(t, ret) }