From aca2c66f64ed03d9d3f562668f6e216e03b6fa66 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 14 Dec 2024 23:03:17 +0100 Subject: [PATCH 1/9] enable testifylint linter Signed-off-by: Matthieu MOREL --- .golangci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 2e72bba..6e0625d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -71,6 +71,8 @@ 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: + enable-all: true linters: fast: false @@ -79,6 +81,7 @@ linters: - gofumpt - goimports - gci + - testifylint disable-all: true issues: From 21d0afc2a392179c1a1a8f41a9ac3c6cad20d9ba Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 14 Dec 2024 23:07:44 +0100 Subject: [PATCH 2/9] Update errors_test.go --- pkg/analyzer/errors_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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{}) } From 8070732c57880c933b8e72f38bd1bf5931f571f1 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 14 Dec 2024 23:09:33 +0100 Subject: [PATCH 3/9] Update diff_test.go --- pkg/analyzer/diff_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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) }) } From 3bb9da8046b44da54a9f4c40d25344e73f70a455 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 14 Dec 2024 23:10:46 +0100 Subject: [PATCH 4/9] Update config_test.go --- pkg/config/config_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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) } From 184eab66b771f0d9a1271d115d231dad6c2b2feb Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 14 Dec 2024 23:13:11 +0100 Subject: [PATCH 5/9] Update errors_test.go --- pkg/section/errors_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/section/errors_test.go b/pkg/section/errors_test.go index 1d54278..8f4e0b8 100644 --- a/pkg/section/errors_test.go +++ b/pkg/section/errors_test.go @@ -8,18 +8,18 @@ import ( ) 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)) + assert.ErrorIs(t, MissingParameterClosingBracketsError, MissingParameterClosingBracketsError) + assert.ErrorIs(t, MoreThanOneOpeningQuotesError, MoreThanOneOpeningQuotesError) + assert.ErrorIs(t, SectionTypeDoesNotAcceptParametersError, SectionTypeDoesNotAcceptParametersError) + assert.ErrorIs(t, SectionTypeDoesNotAcceptPrefixError, SectionTypeDoesNotAcceptPrefixError) + assert.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)) + assert.ErrorIs(t, errorGroup, SectionParsingError{}) + assert.ErrorIs(t, errorGroup, subError) + assert.ErrorIs(t, errorGroup.Wrap("x"), SectionParsingError{}) + assert.ErrorIs(t, errorGroup.Wrap("x"), subError) } From 282bcae0ed90126a8b43f95aab69a9c842fa2783 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 14 Dec 2024 23:14:43 +0100 Subject: [PATCH 6/9] Update errors_test.go --- pkg/section/errors_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/section/errors_test.go b/pkg/section/errors_test.go index 8f4e0b8..385002b 100644 --- a/pkg/section/errors_test.go +++ b/pkg/section/errors_test.go @@ -1,7 +1,6 @@ package section import ( - "errors" "testing" "github.com/stretchr/testify/assert" From 4e1be894fdd2f9b5c436dfeee97821cd0be743a5 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 14 Dec 2024 23:16:51 +0100 Subject: [PATCH 7/9] Update gci_test.go --- pkg/gci/gci_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)) }) From dafaa6650a306e0ce23cdc95a243721ca983259e Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 14 Dec 2024 23:21:40 +0100 Subject: [PATCH 8/9] Update errors_test.go --- pkg/section/errors_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/section/errors_test.go b/pkg/section/errors_test.go index 385002b..ad6032f 100644 --- a/pkg/section/errors_test.go +++ b/pkg/section/errors_test.go @@ -3,22 +3,22 @@ package section import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestErrorMatching(t *testing.T) { - assert.ErrorIs(t, MissingParameterClosingBracketsError, MissingParameterClosingBracketsError) - assert.ErrorIs(t, MoreThanOneOpeningQuotesError, MoreThanOneOpeningQuotesError) - assert.ErrorIs(t, SectionTypeDoesNotAcceptParametersError, SectionTypeDoesNotAcceptParametersError) - assert.ErrorIs(t, SectionTypeDoesNotAcceptPrefixError, SectionTypeDoesNotAcceptPrefixError) - assert.ErrorIs(t, 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.ErrorIs(t, errorGroup, SectionParsingError{}) - assert.ErrorIs(t, errorGroup, subError) - assert.ErrorIs(t, errorGroup.Wrap("x"), SectionParsingError{}) - assert.ErrorIs(t, 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) } From 88bf531c3b09ad851563d5022d2097b213c5f1e1 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 14 Dec 2024 23:22:37 +0100 Subject: [PATCH 9/9] Update .golangci.yml --- .golangci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 6e0625d..6911099 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -72,6 +72,8 @@ linters-settings: # it's a comma-separated list of prefixes local-prefixes: github.com/daixiang0/gci testifylint: + disable: + - useless-assert enable-all: true linters: