Skip to content

Commit 7a4a2fa

Browse files
authored
ci: add more lints (#32)
1 parent 1c1a548 commit 7a4a2fa

File tree

15 files changed

+202
-72
lines changed

15 files changed

+202
-72
lines changed

go/.golangci.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
linters-settings:
2+
errcheck:
3+
check-type-assertions: true
4+
govet:
5+
enable-all: true
6+
7+
linters:
8+
disable-all: true
9+
enable:
10+
# enabled by default
11+
- errcheck
12+
- gosimple
13+
- govet
14+
- ineffassign
15+
- staticcheck
16+
- unused
17+
# disabled by default
18+
- asasalint
19+
- asciicheck
20+
- bidichk
21+
- bodyclose
22+
- canonicalheader
23+
- copyloopvar
24+
- durationcheck
25+
- errname
26+
- errorlint
27+
- exhaustive
28+
- exptostd
29+
- fatcontext
30+
- gocheckcompilerdirectives
31+
- gochecknoinits
32+
- gochecksumtype
33+
- goconst
34+
- gocyclo
35+
- godot
36+
- goimports
37+
- gomoddirectives
38+
- goprintffuncname
39+
- gosec
40+
- iface
41+
- intrange
42+
- loggercheck
43+
- makezero
44+
- mirror
45+
- musttag
46+
- nakedret
47+
- nestif
48+
- nilerr
49+
- nilnesserr
50+
- nilnil
51+
- noctx
52+
- nolintlint
53+
- nonamedreturns
54+
- nosprintfhostport
55+
- perfsprint
56+
- predeclared
57+
- promlinter
58+
- protogetter
59+
- reassign
60+
- recvcheck
61+
- revive
62+
- sloglint
63+
- spancheck
64+
- sqlclosecheck
65+
- stylecheck
66+
- tenv
67+
- testableexamples
68+
- testifylint
69+
- testpackage
70+
- tparallel
71+
- unconvert
72+
- unparam
73+
- usestdlibvars
74+
- usetesting
75+
- wastedassign
76+
- whitespace

go/cmd/snekcheck/errors.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package main
22

33
// Common errors.
44
var (
5-
invalidFileNamesErr = Error{Code: 1, Message: "invalid filenames found"}
6-
noPathsProvidedErr = Error{Code: 2, Message: "no paths provided"}
7-
failedToBuildFileTreeErr = Error{Code: 3, Message: "failed to build file tree"}
5+
errInvalidFileNames = Error{Code: 1, Message: "invalid filenames found"}
6+
errNoPathsProvided = Error{Code: 2, Message: "no paths provided"}
7+
errFailedToBuildFileTree = Error{Code: 3, Message: "failed to build file tree"}
88
)
99

1010
// A command-line error.
1111
type Error struct {
12-
Code uint8
1312
Message string
13+
Code uint8
1414
}
1515

1616
// Returns the error's status code.

go/cmd/snekcheck/errors_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212
func TestError(t *testing.T) {
1313
t.Parallel()
1414
t.Run("Error()", func(t *testing.T) {
15+
t.Parallel()
1516
t.Run("returns the correct error message", func(t *testing.T) {
17+
t.Parallel()
1618
testCases := []string{
1719
"an error occurred",
1820
"yikes!",
@@ -23,6 +25,7 @@ func TestError(t *testing.T) {
2325
}
2426
})
2527
t.Run("formats correctly as an error", func(t *testing.T) {
28+
t.Parallel()
2629
testCases := []string{
2730
"an error occurred",
2831
"yikes!",
@@ -33,6 +36,7 @@ func TestError(t *testing.T) {
3336
}
3437
})
3538
t.Run("can be wrapped and unwrapped", func(t *testing.T) {
39+
t.Parallel()
3640
testCases := []string{
3741
"an error occurred",
3842
"yikes!",
@@ -45,7 +49,9 @@ func TestError(t *testing.T) {
4549
})
4650
})
4751
t.Run("ExitCode()", func(t *testing.T) {
52+
t.Parallel()
4853
t.Run("produces the correct exit code", func(t *testing.T) {
54+
t.Parallel()
4955
testCases := []uint8{
5056
0,
5157
1,

go/cmd/snekcheck/run.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func Run(config Config) cli.Error {
2828
panic("invalid filesystem")
2929
}
3030
if len(config.Paths) == 0 {
31-
return noPathsProvidedErr
31+
return errNoPathsProvided
3232
}
3333

3434
// Build file tree.
@@ -38,7 +38,7 @@ func Run(config Config) cli.Error {
3838
})
3939
for _, path := range config.Paths {
4040
if addPathWithChildren(fileTree, config.Fs, path, config.Depth) != nil {
41-
return failedToBuildFileTreeErr
41+
return errFailedToBuildFileTree
4242
}
4343
}
4444

@@ -124,7 +124,7 @@ func Run(config Config) cli.Error {
124124

125125
// Terminate.
126126
if len(invalidPaths) != 0 {
127-
return invalidFileNamesErr
127+
return errInvalidFileNames
128128
}
129129
return nil
130130
}
@@ -178,7 +178,7 @@ func addPathWithChildren(fileTree tree.UniqueNode[string], fs billy.Filesystem,
178178
return recurse(path, 0)
179179
}
180180

181-
// Parses gitignore patterns in a single directory
181+
// Parses gitignore patterns in a single directory.
182182
func parseGitIgnorePatterns(fs billy.Filesystem, path files.Path) files.GitIgnore {
183183
patterns, ignoreErr := files.ParseGitIgnore(fs, path)
184184
if ignoreErr != nil {

go/cmd/snekcheck/run_test.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99

1010
"github.com/go-git/go-billy/v5"
1111
"github.com/go-git/go-billy/v5/memfs"
12-
"github.com/stretchr/testify/assert"
13-
"github.com/stretchr/testify/require"
1412
"github.com/stretchr/testify/suite"
1513
)
1614

@@ -33,57 +31,57 @@ func (suite *RunTestSuite) SetupSubTest() {
3331
func (suite *RunTestSuite) TestRun() {
3432
suite.Run("Run()", func() {
3533
suite.Run("panics given an invalid file system", func() {
36-
assert.Panics(suite.T(), func() { _ = main.Run(main.Config{Fs: nil}) })
34+
suite.Panics(func() { _ = main.Run(main.Config{Fs: nil}) })
3735
})
3836
suite.Run("returns an error when given no paths", func() {
39-
assert.NotNil(suite.T(), main.Run(main.Config{Fs: memfs.New(), Paths: nil}))
37+
suite.NotNil(main.Run(main.Config{Fs: memfs.New(), Paths: nil}))
4038
})
4139
suite.Run("check", func() {
4240
suite.Run("succeeds with an empty directory", func() {
4341
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: false, Paths: []files.Path{suite.Root}, Verbose: false}
44-
assert.Nil(suite.T(), main.Run(config))
42+
suite.Nil(main.Run(config))
4543
})
4644
suite.Run("succeeds with a single valid file", func() {
4745
validFilename := append(suite.Root, "valid")
48-
require.True(suite.T(), main.IsValid(validFilename.Base()))
46+
suite.Require().True(main.IsValid(validFilename.Base()))
4947
_, createErr := suite.Fs.Create(validFilename.String())
50-
require.Nil(suite.T(), createErr)
48+
suite.Require().NoError(createErr)
5149

5250
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: false, Paths: []files.Path{suite.Root}, Verbose: false}
53-
assert.Nil(suite.T(), main.Run(config))
51+
suite.Nil(main.Run(config))
5452
})
5553
suite.Run("fails with a single invalid file", func() {
5654
invalidFilename := append(suite.Root, "InVaLiD")
57-
require.False(suite.T(), main.IsValid(invalidFilename.Base()))
55+
suite.Require().False(main.IsValid(invalidFilename.Base()))
5856
_, createErr := suite.Fs.Create(invalidFilename.String())
59-
require.Nil(suite.T(), createErr)
57+
suite.Require().NoError(createErr)
6058

6159
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: false, Paths: []files.Path{suite.Root}, Verbose: false}
62-
assert.NotNil(suite.T(), main.Run(config))
60+
suite.NotNil(main.Run(config))
6361
})
6462
})
6563
suite.Run("fix", func() {
6664
suite.Run("succeeds with an empty directory", func() {
6765
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: true, Paths: []files.Path{suite.Root}, Verbose: false}
68-
assert.Nil(suite.T(), main.Run(config))
66+
suite.Nil(main.Run(config))
6967
})
7068
suite.Run("succeeds with a single valid file", func() {
7169
validFilename := append(suite.Root, "valid")
72-
require.True(suite.T(), main.IsValid(validFilename.Base()))
70+
suite.Require().True(main.IsValid(validFilename.Base()))
7371
_, createErr := suite.Fs.Create(validFilename.String())
74-
require.Nil(suite.T(), createErr)
72+
suite.Require().NoError(createErr)
7573

7674
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: true, Paths: []files.Path{suite.Root}, Verbose: false}
77-
assert.Nil(suite.T(), main.Run(config))
75+
suite.Nil(main.Run(config))
7876
})
7977
suite.Run("succeeds with a single invalid file", func() {
8078
invalidFilename := append(suite.Root, "InVaLiD")
81-
require.False(suite.T(), main.IsValid(invalidFilename.Base()))
79+
suite.Require().False(main.IsValid(invalidFilename.Base()))
8280
_, createErr := suite.Fs.Create(invalidFilename.String())
83-
require.Nil(suite.T(), createErr)
81+
suite.Require().NoError(createErr)
8482

8583
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: true, Paths: []files.Path{suite.Root}, Verbose: false}
86-
assert.Nil(suite.T(), main.Run(config))
84+
suite.Nil(main.Run(config))
8785
})
8886
})
8987
})

go/cmd/snekcheck/validator_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
func TestIsValid(t *testing.T) {
1111
t.Parallel()
1212
t.Run("identifies valid file names", func(t *testing.T) {
13+
t.Parallel()
1314
testCases := []string{
1415
"main.go",
1516
"flake.nix",
@@ -23,6 +24,7 @@ func TestIsValid(t *testing.T) {
2324
}
2425
})
2526
t.Run("identifies invalid file names", func(t *testing.T) {
27+
t.Parallel()
2628
testCases := []string{
2729
"Snake",
2830
"snake case 123",

go/internal/files/path_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import (
1414
func TestPath(t *testing.T) {
1515
t.Parallel()
1616
t.Run("NewPath()", func(t *testing.T) {
17+
t.Parallel()
1718
t.Run("creates a path", func(t *testing.T) {
19+
t.Parallel()
1820
testCases := []string{
1921
"",
2022
"longstring",
@@ -27,7 +29,9 @@ func TestPath(t *testing.T) {
2729
})
2830
})
2931
t.Run("Base()", func(t *testing.T) {
32+
t.Parallel()
3033
t.Run("returns the last element", func(t *testing.T) {
34+
t.Parallel()
3135
testCases := []files.Path{
3236
{"dir", "dir", "file.txt"},
3337
{"longstring"},
@@ -38,11 +42,14 @@ func TestPath(t *testing.T) {
3842
}
3943
})
4044
t.Run("panics if the path is empty", func(t *testing.T) {
45+
t.Parallel()
4146
assert.Panics(t, func() { files.Path{}.Base() })
4247
})
4348
})
4449
t.Run("Parent()", func(t *testing.T) {
50+
t.Parallel()
4551
t.Run("returns every element except the last element", func(t *testing.T) {
52+
t.Parallel()
4653
testCases := []files.Path{
4754
{"dir", "dir", "file.txt"},
4855
{"longstring"},
@@ -53,11 +60,14 @@ func TestPath(t *testing.T) {
5360
}
5461
})
5562
t.Run("panics if the path is empty", func(t *testing.T) {
63+
t.Parallel()
5664
assert.Panics(t, func() { files.Path{}.Parent() })
5765
})
5866
})
5967
t.Run("String()", func(t *testing.T) {
68+
t.Parallel()
6069
t.Run("returns the full path", func(t *testing.T) {
70+
t.Parallel()
6171
testCases := []files.Path{
6272
{"dir", "dir", "file.txt"},
6373
{"longstring"},
@@ -68,6 +78,7 @@ func TestPath(t *testing.T) {
6878
}
6979
})
7080
t.Run("formats correctly as a string", func(t *testing.T) {
81+
t.Parallel()
7182
testCases := []files.Path{
7283
{"dir", "dir", "file.txt"},
7384
{"longstring"},

go/internal/patterns/posix_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010

1111
func BenchmarkPosix(b *testing.B) {
1212
b.Run("IsPosixFileName()", func(b *testing.B) {
13-
for i := 0; i < b.N; i++ {
13+
for range b.N {
1414
patterns.IsPosixFileName("Bench mark")
1515
}
1616
})
1717
b.Run("ToPosixFileName()", func(b *testing.B) {
18-
for i := 0; i < b.N; i++ {
18+
for range b.N {
1919
patterns.ToPosixFileName("Bench mark")
2020
}
2121
})
@@ -34,7 +34,9 @@ func FuzzPosix(f *testing.F) {
3434
func TestPosix(t *testing.T) {
3535
t.Parallel()
3636
t.Run("IsPosixFileName()", func(t *testing.T) {
37+
t.Parallel()
3738
t.Run("identifies valid POSIX filenames", func(t *testing.T) {
39+
t.Parallel()
3840
testCases := []string{
3941
"posix",
4042
"POSIX_FILE",
@@ -47,6 +49,7 @@ func TestPosix(t *testing.T) {
4749
}
4850
})
4951
t.Run("identifies invalid POSIX filenames", func(t *testing.T) {
52+
t.Parallel()
5053
testCases := []string{
5154
"-TEST",
5255
"lol@email",
@@ -59,7 +62,9 @@ func TestPosix(t *testing.T) {
5962
})
6063
})
6164
t.Run("ToPosixFileName()", func(t *testing.T) {
65+
t.Parallel()
6266
t.Run("does not change valid POSIX filenames", func(t *testing.T) {
67+
t.Parallel()
6368
testCases := []string{
6469
"POSIX",
6570
".POSIX_123_.md",
@@ -71,6 +76,7 @@ func TestPosix(t *testing.T) {
7176
}
7277
})
7378
t.Run("converts invalid POSIX filenames to valid POSIX filenames", func(t *testing.T) {
79+
t.Parallel()
7480
testCases := []struct {
7581
input string
7682
output string

0 commit comments

Comments
 (0)