Skip to content

Commit 597c865

Browse files
Update linter config (#75)
1 parent 91d1e9b commit 597c865

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

.golangci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ linters:
3636
- nestif # cyclop does this
3737
- nlreturn # Similar to wsl, I think best left to judgement
3838
- nonamedreturns # Named returns are often helpful, it's naked returns that are the issue
39+
- noinlineerr # This is more readable in some cases
3940
- paralleltest # I've never had Go tests take longer than a few seconds, it's fine
4041
- thelper # Everything in here is a helper basically
4142
- unparam # gopls is better and more subtle
@@ -54,7 +55,7 @@ linters:
5455
linters:
5556
- prealloc # These kinds of optimisations will make no difference to test code
5657
- gosec # Tests don't need security stuff
57-
- goconst
58+
- goconst # Nah
5859

5960
paths:
6061
- internal/diff
@@ -161,6 +162,7 @@ linters:
161162
- fmt\.(Fp|P)rint(ln|f)?
162163
- strings.Builder.Write(String|Byte)?
163164
- bytes.Buffer.Write(String|Byte)?
165+
- os.File.Close?
164166

165167
- name: flag-parameter
166168
disabled: true # As far as I can work out this just doesn't like bools

Taskfile.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tasks:
99
default:
1010
desc: List all available tasks
1111
silent: true
12+
internal: true
1213
cmds:
1314
- task --list
1415

@@ -25,18 +26,17 @@ tasks:
2526
desc: Run go fmt on all source files
2627
sources:
2728
- "**/*.go"
28-
preconditions:
29-
- sh: command -v golines
30-
msg: golines not installed, run `go install github.com/segmentio/golines@latest`
29+
- .golangci.yml
3130
cmds:
32-
- go fmt ./...
33-
- golines . --ignore-generated --write-output --max-len 120
31+
- golangci-lint fmt
3432

3533
test:
3634
desc: Run the test suite
3735
sources:
3836
- "**/*.go"
39-
- testdata/**/*.snap.txt
37+
- go.mod
38+
- go.sum
39+
- "**/testdata/**/*"
4040
cmds:
4141
- go test -race ./... {{ .CLI_ARGS }}
4242

@@ -52,8 +52,6 @@ tasks:
5252
sources:
5353
- "**/*.go"
5454
- .golangci.yml
55-
deps:
56-
- fmt
5755
preconditions:
5856
- sh: command -v golangci-lint
5957
msg: golangci-lint not installed, see https://golangci-lint.run/usage/install/#local-installation

test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ func CaptureOutput(tb testing.TB, fn func() error) (stdout, stderr string) {
446446
if _, err := io.Copy(buf, stdoutReader); err != nil {
447447
tb.Fatalf("CaptureOutput: failed to copy from stdout reader: %v", err)
448448
}
449+
449450
stdoutCapture <- buf.String()
450451
}(&wg)
451452

@@ -459,6 +460,7 @@ func CaptureOutput(tb testing.TB, fn func() error) (stdout, stderr string) {
459460
if _, err := io.Copy(buf, stderrReader); err != nil {
460461
tb.Fatalf("CaptureOutput: failed to copy from stderr reader: %v", err)
461462
}
463+
462464
stderrCapture <- buf.String()
463465
}(&wg)
464466

test_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ import (
1414
"go.followtheprocess.codes/test"
1515
)
1616

17-
var update = flag.Bool("update", false, "Update snapshots")
17+
var (
18+
update = flag.Bool("update", false, "Update snapshots")
19+
clean = flag.Bool("clean", false, "Erase all snapshots and recreate them from scratch")
20+
)
1821

1922
// TB is a fake implementation of [testing.TB] that simply records in internal
2023
// state whether or not it would have failed and what it would have written.
2124
type TB struct {
2225
testing.TB
26+
2327
out io.Writer
2428
failed bool
2529
}
@@ -434,7 +438,7 @@ func TestTest(t *testing.T) {
434438
t.Run(tt.name, func(t *testing.T) {
435439
buf := &bytes.Buffer{}
436440
tb := &TB{out: buf}
437-
snap := snapshot.New(t, snapshot.Update(*update), snapshot.Color(false))
441+
snap := snapshot.New(t, snapshot.Update(*update), snapshot.Clean(*clean), snapshot.Color(false))
438442

439443
if tb.failed {
440444
t.Fatalf("%s initial failed state should be false", tt.name)

0 commit comments

Comments
 (0)