Skip to content

Commit bc528ba

Browse files
authored
ci: disable noisy linters (#40)
1 parent 9c976dd commit bc528ba

22 files changed

+175
-59
lines changed

go/.golangci.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
1+
formatters:
2+
enable:
3+
- gci
4+
- gofmt
5+
- golines
16
linters:
27
default: all
8+
disable:
9+
- cyclop
10+
- depguard
11+
- dupl
12+
- err113
13+
- exhaustruct
14+
- forbidigo
15+
- funlen
16+
- gocognit
17+
- gocritic
18+
- ireturn
19+
- lll
20+
- mnd
21+
- paralleltest
22+
- revive
23+
- varnamelen
24+
- wrapcheck
25+
- wsl
326
settings:
427
errcheck:
528
check-type-assertions: true
629
govet:
730
enable-all: true
8-
931
version: "2"

go/cmd/snekcheck/errors_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package main_test
33
import (
44
"errors"
55
"fmt"
6-
main "snekcheck/cmd/snekcheck"
76
"testing"
87

98
"github.com/stretchr/testify/assert"
9+
main "snekcheck/cmd/snekcheck"
1010
)
1111

1212
func TestError(t *testing.T) {
@@ -44,7 +44,11 @@ func TestError(t *testing.T) {
4444
}
4545
for _, input := range testCases {
4646
baseError := main.Error{Message: input}
47-
assert.Equal(t, baseError, errors.Unwrap(fmt.Errorf("wrapped error: %w", baseError)))
47+
assert.Equal(
48+
t,
49+
baseError,
50+
errors.Unwrap(fmt.Errorf("wrapped error: %w", baseError)),
51+
)
4852
}
4953
})
5054
})

go/cmd/snekcheck/main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212
"math"
1313
"os"
1414
"path/filepath"
15-
"snekcheck/internal/cli"
16-
"snekcheck/internal/files"
1715

1816
"github.com/go-git/go-billy/v5/osfs"
1917
"github.com/spf13/pflag"
18+
"snekcheck/internal/cli"
19+
"snekcheck/internal/files"
2020
)
2121

2222
// The snekcheck CLI builds a runtime configuration for the core process.
@@ -32,9 +32,18 @@ func main() {
3232
panic("failed to initialize flag set")
3333
}
3434
flagSet.Usage = func() {
35-
fmt.Fprintf(os.Stderr, "Usage:\n snekcheck <flag> ... <path> ...\n\n%s", flagSet.FlagUsages())
35+
fmt.Fprintf(
36+
os.Stderr,
37+
"Usage:\n snekcheck <flag> ... <path> ...\n\n%s",
38+
flagSet.FlagUsages(),
39+
)
3640
}
37-
depth := flagSet.UintP("depth", "d", math.MaxUint8, "The number of levels to descend into a directory")
41+
depth := flagSet.UintP(
42+
"depth",
43+
"d",
44+
math.MaxUint8,
45+
"The number of levels to descend into a directory",
46+
)
3847
fix := flagSet.BoolP("fix", "f", false, "Whether to correct invalid filenames")
3948
help := flagSet.BoolP("help", "h", false, "Print usage help")
4049
verbose := flagSet.BoolP("verbose", "v", false, "Whether to print filenames")

go/cmd/snekcheck/run.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import (
44
"fmt"
55
"slices"
66

7+
"github.com/fatih/color"
8+
"github.com/go-git/go-billy/v5"
79
"snekcheck/internal/cli"
810
"snekcheck/internal/files"
911
"snekcheck/internal/patterns"
1012
"snekcheck/internal/tree"
11-
12-
"github.com/fatih/color"
13-
"github.com/go-git/go-billy/v5"
1413
)
1514

1615
// A runtime configuration for snekcheck.
@@ -59,6 +58,7 @@ func Run(config Config) cli.Error {
5958
fmt.Print(color.GreenString("."))
6059
}
6160
validPaths = append(validPaths, path)
61+
6262
return
6363
}
6464
if !config.Fix {
@@ -68,6 +68,7 @@ func Run(config Config) cli.Error {
6868
fmt.Print(color.RedString("."))
6969
}
7070
invalidPaths = append(invalidPaths, path)
71+
7172
return
7273
}
7374
var newPath files.Path
@@ -117,7 +118,11 @@ func Run(config Config) cli.Error {
117118
fmt.Print("\n\n")
118119
}
119120
if config.Fix {
120-
fmt.Printf("%s valid filenames, %s filenames changed\n", color.GreenString("%d", len(validPaths)), color.YellowString("%d", len(renamedPaths)))
121+
fmt.Printf(
122+
"%s valid filenames, %s filenames changed\n",
123+
color.GreenString("%d", len(validPaths)),
124+
color.YellowString("%d", len(renamedPaths)),
125+
)
121126
} else {
122127
fmt.Printf("%s valid filenames, %s invalid filenames\n", color.GreenString("%d", len(validPaths)), color.RedString("%d", len(invalidPaths)))
123128
}
@@ -126,11 +131,17 @@ func Run(config Config) cli.Error {
126131
if len(invalidPaths) != 0 {
127132
return errInvalidFileNames
128133
}
134+
129135
return nil
130136
}
131137

132138
// Recursively adds matching child paths to a file tree, up to a maximum depth.
133-
func addPathWithChildren(fileTree tree.UniqueNode[string], fs billy.Filesystem, path files.Path, maxDepth uint) error {
139+
func addPathWithChildren(
140+
fileTree tree.UniqueNode[string],
141+
fs billy.Filesystem,
142+
path files.Path,
143+
maxDepth uint,
144+
) error {
134145
if fileTree == nil {
135146
panic("invalid file tree")
136147
}
@@ -172,6 +183,7 @@ func addPathWithChildren(fileTree tree.UniqueNode[string], fs billy.Filesystem,
172183
return err
173184
}
174185
}
186+
175187
return nil
176188
}
177189

@@ -184,6 +196,7 @@ func parseGitIgnorePatterns(fs billy.Filesystem, path files.Path) files.GitIgnor
184196
if ignoreErr != nil {
185197
patterns = nil
186198
}
199+
187200
return patterns
188201
}
189202

@@ -195,5 +208,6 @@ func loadGlobalGitIgnore(fs billy.Filesystem) files.GitIgnore {
195208
fmt.Printf("WARN %s", ignoreErr)
196209
globalIgnorePatterns = nil
197210
}
211+
198212
return globalIgnorePatterns
199213
}

go/cmd/snekcheck/run_test.go

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package main_test
33
import (
44
"math"
55
"os"
6-
main "snekcheck/cmd/snekcheck"
7-
"snekcheck/internal/files"
86
"testing"
97

108
"github.com/go-git/go-billy/v5"
119
"github.com/go-git/go-billy/v5/memfs"
1210
"github.com/stretchr/testify/suite"
11+
main "snekcheck/cmd/snekcheck"
12+
"snekcheck/internal/files"
1313
)
1414

1515
type RunTestSuite struct {
@@ -38,7 +38,13 @@ func (suite *RunTestSuite) TestRun() {
3838
})
3939
suite.Run("check", func() {
4040
suite.Run("succeeds with an empty directory", func() {
41-
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: false, Paths: []files.Path{suite.Root}, Verbose: false}
41+
config := main.Config{
42+
Depth: math.MaxUint,
43+
Fs: suite.Fs,
44+
Fix: false,
45+
Paths: []files.Path{suite.Root},
46+
Verbose: false,
47+
}
4248
suite.Nil(main.Run(config))
4349
})
4450
suite.Run("succeeds with a single valid file", func() {
@@ -47,7 +53,13 @@ func (suite *RunTestSuite) TestRun() {
4753
_, createErr := suite.Fs.Create(validFilename.String())
4854
suite.Require().NoError(createErr)
4955

50-
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: false, Paths: []files.Path{suite.Root}, Verbose: false}
56+
config := main.Config{
57+
Depth: math.MaxUint,
58+
Fs: suite.Fs,
59+
Fix: false,
60+
Paths: []files.Path{suite.Root},
61+
Verbose: false,
62+
}
5163
suite.Nil(main.Run(config))
5264
})
5365
suite.Run("fails with a single invalid file", func() {
@@ -56,13 +68,25 @@ func (suite *RunTestSuite) TestRun() {
5668
_, createErr := suite.Fs.Create(invalidFilename.String())
5769
suite.Require().NoError(createErr)
5870

59-
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: false, Paths: []files.Path{suite.Root}, Verbose: false}
71+
config := main.Config{
72+
Depth: math.MaxUint,
73+
Fs: suite.Fs,
74+
Fix: false,
75+
Paths: []files.Path{suite.Root},
76+
Verbose: false,
77+
}
6078
suite.NotNil(main.Run(config))
6179
})
6280
})
6381
suite.Run("fix", func() {
6482
suite.Run("succeeds with an empty directory", func() {
65-
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: true, Paths: []files.Path{suite.Root}, Verbose: false}
83+
config := main.Config{
84+
Depth: math.MaxUint,
85+
Fs: suite.Fs,
86+
Fix: true,
87+
Paths: []files.Path{suite.Root},
88+
Verbose: false,
89+
}
6690
suite.Nil(main.Run(config))
6791
})
6892
suite.Run("succeeds with a single valid file", func() {
@@ -71,7 +95,13 @@ func (suite *RunTestSuite) TestRun() {
7195
_, createErr := suite.Fs.Create(validFilename.String())
7296
suite.Require().NoError(createErr)
7397

74-
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: true, Paths: []files.Path{suite.Root}, Verbose: false}
98+
config := main.Config{
99+
Depth: math.MaxUint,
100+
Fs: suite.Fs,
101+
Fix: true,
102+
Paths: []files.Path{suite.Root},
103+
Verbose: false,
104+
}
75105
suite.Nil(main.Run(config))
76106
})
77107
suite.Run("succeeds with a single invalid file", func() {
@@ -80,7 +110,13 @@ func (suite *RunTestSuite) TestRun() {
80110
_, createErr := suite.Fs.Create(invalidFilename.String())
81111
suite.Require().NoError(createErr)
82112

83-
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: true, Paths: []files.Path{suite.Root}, Verbose: false}
113+
config := main.Config{
114+
Depth: math.MaxUint,
115+
Fs: suite.Fs,
116+
Fix: true,
117+
Paths: []files.Path{suite.Root},
118+
Verbose: false,
119+
}
84120
suite.Nil(main.Run(config))
85121
})
86122
suite.Run("condenses separators into one underscore", func() {
@@ -89,7 +125,13 @@ func (suite *RunTestSuite) TestRun() {
89125
_, createErr := suite.Fs.Create(invalidFilename.String())
90126
suite.Require().NoError(createErr)
91127

92-
config := main.Config{Depth: math.MaxUint, Fs: suite.Fs, Fix: true, Paths: []files.Path{suite.Root}, Verbose: false}
128+
config := main.Config{
129+
Depth: math.MaxUint,
130+
Fs: suite.Fs,
131+
Fix: true,
132+
Paths: []files.Path{suite.Root},
133+
Verbose: false,
134+
}
93135
suite.Nil(main.Run(config))
94136
})
95137
})

go/cmd/snekcheck/validator.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package main
22

33
import (
4-
"snekcheck/internal/patterns"
54
"strings"
5+
6+
"snekcheck/internal/patterns"
67
)
78

89
// Determines if a filename is valid according to snekcheck's opinion.
@@ -18,5 +19,6 @@ func isAlmostScreamingSnakeCase(name string) bool {
1819
if lastIndex == -1 {
1920
return patterns.IsScreamingSnakeCase(name)
2021
}
22+
2123
return patterns.IsScreamingSnakeCase(name[:lastIndex]) && patterns.IsSnakeCase(name[lastIndex:])
2224
}

go/cmd/snekcheck/validator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package main_test
22

33
import (
4-
main "snekcheck/cmd/snekcheck"
54
"testing"
65

76
"github.com/stretchr/testify/assert"
7+
main "snekcheck/cmd/snekcheck"
88
)
99

1010
func TestIsValid(t *testing.T) {

go/internal/files/git.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ func (gi GitIgnore) Match(path Path, isDir bool) bool {
1919
return gitignore.NewMatcher(gi).Match(path, isDir)
2020
}
2121

22-
var basePatterns = []gitignore.Pattern{gitignore.ParsePattern(".git/", nil)}
23-
2422
// Parses the list of global gitignore patterns.
2523
func GlobalGitIgnorePatterns(fs billy.Filesystem) ([]gitignore.Pattern, error) {
24+
basePatterns := []gitignore.Pattern{gitignore.ParsePattern(".git/", nil)}
2625
systemPatterns, systemErr := gitignore.LoadSystemPatterns(fs)
2726
userPatterns, userErr := gitignore.LoadGlobalPatterns(fs)
2827

2928
allErr := errors.Join(systemErr, userErr)
3029
if allErr != nil {
3130
return nil, fmt.Errorf("failed to load gitignore patterns: %w", allErr)
3231
}
32+
3333
return slices.Concat(basePatterns, systemPatterns, userPatterns), nil
3434
}
3535

@@ -55,7 +55,11 @@ func parseGitIgnoreFile(fs billy.Filesystem, path Path) ([]gitignore.Pattern, er
5555
return nil, openErr
5656
}
5757

58-
defer f.Close()
58+
defer func() {
59+
if err := f.Close(); err != nil {
60+
panic(err)
61+
}
62+
}()
5963
var patterns []gitignore.Pattern
6064

6165
scanner := bufio.NewScanner(f)

go/internal/files/path_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7-
"snekcheck/internal/files"
87
"strings"
98
"testing"
109

1110
"github.com/stretchr/testify/assert"
11+
"snekcheck/internal/files"
1212
)
1313

1414
func TestPath(t *testing.T) {

go/internal/patterns/posix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ func IsPosixFileName(s string) bool {
2626
func ToPosixFileName(s string) string {
2727
s = spaces.ReplaceAllLiteralString(s, "_")
2828
s = invalidPosixFileNameCharacters.ReplaceAllLiteralString(s, "")
29+
2930
return s[:min(len(s), 255)]
3031
}

0 commit comments

Comments
 (0)