Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable testifylint linter #223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -79,6 +83,7 @@ linters:
- gofumpt
- goimports
- gci
- testifylint
disable-all: true

issues:
Expand Down
5 changes: 3 additions & 2 deletions pkg/analyzer/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
})
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/analyzer/errors_test.go
Original file line number Diff line number Diff line change
@@ -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{})
}
7 changes: 4 additions & 3 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/daixiang0/gci/pkg/section"
)
Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/gci/gci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down
21 changes: 10 additions & 11 deletions pkg/section/errors_test.go
Original file line number Diff line number Diff line change
@@ -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)
}