diff --git a/cmd/test.go b/cmd/test.go index 256bedb8..4c0ac794 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -200,7 +200,7 @@ func opaTest(args []string) int { AddCustomBuiltins(builtins.TestContextBuiltins()). Filter(testParams.runRegex) - for i := 0; i < testParams.count; i++ { + for range testParams.count { exitCode := runTests(ctx, txn, runner, testReporter(cov, modules)) if exitCode != 0 { return exitCode diff --git a/go.mod b/go.mod index 2da47f94..52992cf7 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/styrainc/regal -go 1.21 // any officially supported Golang version should be OK +go 1.22 toolchain go1.22.0 diff --git a/internal/lsp/commands/parse_test.go b/internal/lsp/commands/parse_test.go index 13f4b84c..3a670932 100644 --- a/internal/lsp/commands/parse_test.go +++ b/internal/lsp/commands/parse_test.go @@ -38,8 +38,6 @@ func TestParse(t *testing.T) { } for name, tc := range testCases { - tc := tc - t.Run(name, func(t *testing.T) { t.Parallel() @@ -92,8 +90,6 @@ func TestParse_Errors(t *testing.T) { } for name, tc := range testCases { - tc := tc - t.Run(name, func(t *testing.T) { t.Parallel() diff --git a/internal/lsp/documentsymbol_test.go b/internal/lsp/documentsymbol_test.go index c773d815..c8b1646e 100644 --- a/internal/lsp/documentsymbol_test.go +++ b/internal/lsp/documentsymbol_test.go @@ -70,8 +70,6 @@ func TestRefToString(t *testing.T) { } for _, tc := range cases { - tc := tc - t.Run(tc.title, func(t *testing.T) { t.Parallel() @@ -131,8 +129,6 @@ func TestDocumentSymbols(t *testing.T) { } for _, tc := range cases { - tc := tc - t.Run(tc.title, func(t *testing.T) { t.Parallel() @@ -219,8 +215,6 @@ func TestSimplifyType(t *testing.T) { } for _, tc := range cases { - tc := tc - t.Run(tc.input, func(t *testing.T) { t.Parallel() diff --git a/internal/lsp/uri/uri_test.go b/internal/lsp/uri/uri_test.go index d2d843f6..ed77fc33 100644 --- a/internal/lsp/uri/uri_test.go +++ b/internal/lsp/uri/uri_test.go @@ -29,15 +29,13 @@ func TestPathToURI(t *testing.T) { } for label, tc := range testCases { - tt := tc - t.Run(label, func(t *testing.T) { t.Parallel() - got := FromPath(clients.IdentifierGeneric, tt.path) + got := FromPath(clients.IdentifierGeneric, tc.path) - if got != tt.want { - t.Errorf("got %q, want %q", got, tt.want) + if got != tc.want { + t.Errorf("got %q, want %q", got, tc.want) } }) } @@ -69,15 +67,13 @@ func TestPathToURI_VSCode(t *testing.T) { } for label, tc := range testCases { - tt := tc - t.Run(label, func(t *testing.T) { t.Parallel() - got := FromPath(clients.IdentifierVSCode, tt.path) + got := FromPath(clients.IdentifierVSCode, tc.path) - if got != tt.want { - t.Errorf("got %q, want %q", got, tt.want) + if got != tc.want { + t.Errorf("got %q, want %q", got, tc.want) } }) } @@ -105,14 +101,12 @@ func TestURIToPath(t *testing.T) { } for label, tc := range testCases { - tt := tc - t.Run(label, func(t *testing.T) { t.Parallel() - got := ToPath(clients.IdentifierGeneric, tt.uri) - if got != tt.want { - t.Errorf("got %q, want %q", got, tt.want) + got := ToPath(clients.IdentifierGeneric, tc.uri) + if got != tc.want { + t.Errorf("got %q, want %q", got, tc.want) } }) } @@ -157,14 +151,12 @@ func TestURIToPath_VSCode(t *testing.T) { } for label, tc := range testCases { - tt := tc - t.Run(label, func(t *testing.T) { t.Parallel() - got := ToPath(clients.IdentifierVSCode, tt.uri) - if got != tt.want { - t.Errorf("got %q, want %q", got, tt.want) + got := ToPath(clients.IdentifierVSCode, tc.uri) + if got != tc.want { + t.Errorf("got %q, want %q", got, tc.want) } }) } diff --git a/internal/novelty/holidays.go b/internal/novelty/holidays.go index ab188769..dc6543d7 100644 --- a/internal/novelty/holidays.go +++ b/internal/novelty/holidays.go @@ -41,7 +41,7 @@ func HappyHolidays() error { ) allSprites.Sprites = append(allSprites.Sprites, messageSprite) - for i := 0; i < 30; i++ { + for range 30 { //nolint:gosec flakeX := rand.Intn(width) //nolint:gosec diff --git a/pkg/config/filter_test.go b/pkg/config/filter_test.go index b07159b3..1c7b6df4 100644 --- a/pkg/config/filter_test.go +++ b/pkg/config/filter_test.go @@ -86,8 +86,6 @@ func TestFilterIgnoredPaths(t *testing.T) { } for name, tc := range testCases { - tc := tc - t.Run(name, func(t *testing.T) { t.Parallel() diff --git a/pkg/fixer/fixes/fmt_test.go b/pkg/fixer/fixes/fmt_test.go index fc5dbbe2..83ed867c 100644 --- a/pkg/fixer/fixes/fmt_test.go +++ b/pkg/fixer/fixes/fmt_test.go @@ -52,8 +52,6 @@ allow := true } for testName, tc := range testCases { - tc := tc - t.Run(testName, func(t *testing.T) { t.Parallel() diff --git a/pkg/fixer/fixes/nowhitespacecomment_test.go b/pkg/fixer/fixes/nowhitespacecomment_test.go index 3a9813ea..71c457e1 100644 --- a/pkg/fixer/fixes/nowhitespacecomment_test.go +++ b/pkg/fixer/fixes/nowhitespacecomment_test.go @@ -125,8 +125,6 @@ func TestNoWhitespaceComment(t *testing.T) { } for testName, tc := range testCases { - tc := tc - nwc := NoWhitespaceComment{} t.Run(testName, func(t *testing.T) { diff --git a/pkg/fixer/fixes/useassignmentoperator_test.go b/pkg/fixer/fixes/useassignmentoperator_test.go index a3a5c7d5..9a6a124d 100644 --- a/pkg/fixer/fixes/useassignmentoperator_test.go +++ b/pkg/fixer/fixes/useassignmentoperator_test.go @@ -147,8 +147,6 @@ allow := true } for testName, tc := range testCases { - tc := tc - t.Run(testName, func(t *testing.T) { t.Parallel() diff --git a/pkg/linter/linter_test.go b/pkg/linter/linter_test.go index 3d852a81..4bcf0cf7 100644 --- a/pkg/linter/linter_test.go +++ b/pkg/linter/linter_test.go @@ -263,46 +263,45 @@ or := 1 } for _, tc := range tests { - tt := tc - t.Run(tt.name, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { t.Parallel() linter := NewLinter() - linter = linter.WithRootDir(tt.rootDir) + linter = linter.WithRootDir(tc.rootDir) - if tt.userConfig != nil { - linter = linter.WithUserConfig(*tt.userConfig) + if tc.userConfig != nil { + linter = linter.WithUserConfig(*tc.userConfig) } - if tt.ignoreFilesFlag != nil { - linter = linter.WithIgnore(tt.ignoreFilesFlag) + if tc.ignoreFilesFlag != nil { + linter = linter.WithIgnore(tc.ignoreFilesFlag) } - input := test.InputPolicy(tt.filename, policy) + input := test.InputPolicy(tc.filename, policy) linter = linter.WithInputModules(&input) result := testutil.Must(linter.Lint(context.Background()))(t) - if len(result.Violations) != len(tt.expViolations) { + if len(result.Violations) != len(tc.expViolations) { t.Fatalf("expected %d violation, got %d: %v", - len(tt.expViolations), + len(tc.expViolations), len(result.Violations), result.Violations, ) } for idx, violation := range result.Violations { - if violation.Title != tt.expViolations[idx] { - t.Errorf("expected first violation to be '%s', got %s", tt.expViolations[idx], result.Violations[0].Title) + if violation.Title != tc.expViolations[idx] { + t.Errorf("expected first violation to be '%s', got %s", tc.expViolations[idx], result.Violations[0].Title) } } - if len(tt.expLevels) > 0 { + if len(tc.expLevels) > 0 { for idx, violation := range result.Violations { - if violation.Level != tt.expLevels[idx] { - t.Errorf("expected first violation to be '%s', got %s", tt.expLevels[idx], result.Violations[0].Level) + if violation.Level != tc.expLevels[idx] { + t.Errorf("expected first violation to be '%s', got %s", tc.expLevels[idx], result.Violations[0].Level) } } } diff --git a/pkg/rules/fmt_test.go b/pkg/rules/fmt_test.go index 88b3fd1e..25a2bb3f 100644 --- a/pkg/rules/fmt_test.go +++ b/pkg/rules/fmt_test.go @@ -44,8 +44,6 @@ func TestFmtRuleFail(t *testing.T) { } for name, tc := range testCases { - tc := tc - t.Run(name, func(t *testing.T) { t.Parallel()