From 119a0eea54ecea7c1fa65a03a0a0009429203553 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 14 Dec 2024 23:26:32 +0100 Subject: [PATCH] enable testifylint linter Signed-off-by: Matthieu MOREL --- .golangci.yml | 5 +++++ pkg/analyzer/diff_test.go | 5 +++-- pkg/analyzer/errors_test.go | 3 +-- pkg/config/config_test.go | 7 ++++--- pkg/gci/gci_test.go | 2 +- pkg/section/errors_test.go | 21 ++++++++++----------- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 2e72bba..6911099 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -71,6 +71,10 @@ linters-settings: # put imports beginning with prefix after 3rd-party packages; # it's a comma-separated list of prefixes local-prefixes: github.com/daixiang0/gci + testifylint: + disable: + - useless-assert + enable-all: true linters: fast: false @@ -79,6 +83,7 @@ linters: - gofumpt - goimports - gci + - testifylint disable-all: true issues: diff --git a/pkg/analyzer/diff_test.go b/pkg/analyzer/diff_test.go index 5ed9b19..8544f64 100644 --- a/pkg/analyzer/diff_test.go +++ b/pkg/analyzer/diff_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "golang.org/x/tools/go/analysis" "github.com/daixiang0/gci/pkg/analyzer" @@ -113,14 +114,14 @@ import ( t.Run(tt.name, func(t *testing.T) { fset := token.NewFileSet() f, err := parser.ParseFile(fset, "analyzer.go", tt.unformattedFile, 0) - assert.NoError(t, err) + require.NoError(t, err) actualFix, err := analyzer.GetSuggestedFix(fset.File(f.Pos()), []byte(tt.unformattedFile), []byte(formattedFile)) if tt.expectedErr != "" { assert.ErrorContains(t, err, tt.expectedErr) return } - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, tt.expectedFix, actualFix) }) } diff --git a/pkg/analyzer/errors_test.go b/pkg/analyzer/errors_test.go index b588053..36d1f18 100644 --- a/pkg/analyzer/errors_test.go +++ b/pkg/analyzer/errors_test.go @@ -1,12 +1,11 @@ package analyzer import ( - "errors" "testing" "github.com/stretchr/testify/assert" ) func TestInvalidNumberOfFiles(t *testing.T) { - assert.True(t, errors.Is(InvalidNumberOfFilesInAnalysis{1, 2}, InvalidNumberOfFilesInAnalysis{})) + assert.ErrorIs(t, InvalidNumberOfFilesInAnalysis{1, 2}, InvalidNumberOfFilesInAnalysis{}) } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 9a41d5d..6e9dbad 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/daixiang0/gci/pkg/section" ) @@ -14,7 +15,7 @@ func TestParseOrder(t *testing.T) { SectionStrings: []string{"default", "prefix(github/daixiang0/gci)", "prefix(github/daixiang0/gai)"}, } gciCfg, err := cfg.Parse() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, section.SectionList{section.Default{}, section.Custom{Prefix: "github/daixiang0/gai"}, section.Custom{Prefix: "github/daixiang0/gci"}}, gciCfg.Sections) } @@ -26,7 +27,7 @@ func TestParseCustomOrder(t *testing.T) { }, } gciCfg, err := cfg.Parse() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, section.SectionList{section.Default{}, section.Custom{Prefix: "github/daixiang0/gci"}, section.Custom{Prefix: "github/daixiang0/gai"}}, gciCfg.Sections) } @@ -39,6 +40,6 @@ func TestParseNoLexOrder(t *testing.T) { } gciCfg, err := cfg.Parse() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, section.SectionList{section.Default{}, section.Custom{Prefix: "github/daixiang0/gci"}, section.Custom{Prefix: "github/daixiang0/gai"}}, gciCfg.Sections) } diff --git a/pkg/gci/gci_test.go b/pkg/gci/gci_test.go index f6db3e0..dd8fda1 100644 --- a/pkg/gci/gci_test.go +++ b/pkg/gci/gci_test.go @@ -33,7 +33,7 @@ func TestRun(t *testing.T) { t.Fatal(err) } - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCases[i].in, string(old)) assert.Equal(t, testCases[i].out, string(new)) }) diff --git a/pkg/section/errors_test.go b/pkg/section/errors_test.go index 1d54278..ad6032f 100644 --- a/pkg/section/errors_test.go +++ b/pkg/section/errors_test.go @@ -1,25 +1,24 @@ package section import ( - "errors" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestErrorMatching(t *testing.T) { - assert.True(t, errors.Is(MissingParameterClosingBracketsError, MissingParameterClosingBracketsError)) - assert.True(t, errors.Is(MoreThanOneOpeningQuotesError, MoreThanOneOpeningQuotesError)) - assert.True(t, errors.Is(SectionTypeDoesNotAcceptParametersError, SectionTypeDoesNotAcceptParametersError)) - assert.True(t, errors.Is(SectionTypeDoesNotAcceptPrefixError, SectionTypeDoesNotAcceptPrefixError)) - assert.True(t, errors.Is(SectionTypeDoesNotAcceptSuffixError, SectionTypeDoesNotAcceptSuffixError)) + require.ErrorIs(t, MissingParameterClosingBracketsError, MissingParameterClosingBracketsError) + require.ErrorIs(t, MoreThanOneOpeningQuotesError, MoreThanOneOpeningQuotesError) + require.ErrorIs(t, SectionTypeDoesNotAcceptParametersError, SectionTypeDoesNotAcceptParametersError) + require.ErrorIs(t, SectionTypeDoesNotAcceptPrefixError, SectionTypeDoesNotAcceptPrefixError) + require.ErrorIs(t, SectionTypeDoesNotAcceptSuffixError, SectionTypeDoesNotAcceptSuffixError) } func TestErrorClass(t *testing.T) { subError := MissingParameterClosingBracketsError errorGroup := SectionParsingError{subError} - assert.True(t, errors.Is(errorGroup, SectionParsingError{})) - assert.True(t, errors.Is(errorGroup, subError)) - assert.True(t, errors.Is(errorGroup.Wrap("x"), SectionParsingError{})) - assert.True(t, errors.Is(errorGroup.Wrap("x"), subError)) + require.ErrorIs(t, errorGroup, SectionParsingError{}) + require.ErrorIs(t, errorGroup, subError) + require.ErrorIs(t, errorGroup.Wrap("x"), SectionParsingError{}) + require.ErrorIs(t, errorGroup.Wrap("x"), subError) }