Skip to content

Commit 3d433fe

Browse files
authoredApr 22, 2024
Lint: lint and fix src/{os,reflect} (#4228)
* lint: expand to src/{os,reflect}, fix or suppress what it found * internal/tools/tools.go: the tools idiom requires a build tag guard to avoid go test complaints
1 parent 1154212 commit 3d433fe

File tree

7 files changed

+20
-10
lines changed

7 files changed

+20
-10
lines changed
 

‎GNUmakefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,9 @@ deb: build/release
915915
endif
916916

917917
lint:
918-
# Only run on compiler dir for now, expand as we clean up other dirs
919-
# This obviously won't scale, but it's a start, and it's fast
920-
go run github.com/mgechev/revive --version
921-
go run github.com/mgechev/revive --config revive.toml compiler/...
918+
go run github.com/mgechev/revive -version
919+
# TODO: lint more directories!
920+
# revive.toml isn't flexible enough to filter out just one kind of error from a checker, so do it with grep here.
921+
# Can't use grep with friendly formatter. Plain output isn't too bad, though.
922+
# Use 'grep .' to get rid of stray blank line
923+
go run github.com/mgechev/revive -config revive.toml compiler/... src/{os,reflect}/*.go | grep -v "should have comment or be unexported" | grep '.' | awk '{print}; END {exit NR>0}'

‎internal/tools/tools.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build tools
2+
13
// Install linter versions specified in go.mod
24
// See https://marcofranssen.nl/manage-go-tools-via-go-modules for idom
35
package tools

‎revive.toml

+5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ warningCode = 0
66

77
# Enable these as we fix them
88
[rule.blank-imports]
9+
Exclude=["src/os/file_other.go"]
910
[rule.context-as-argument]
1011
[rule.context-keys-type]
1112
[rule.dot-imports]
13+
Exclude=["**/*_test.go"]
1214
[rule.error-return]
1315
[rule.error-strings]
1416
[rule.error-naming]
1517
[rule.exported]
18+
Exclude=["src/reflect/*.go"]
1619
[rule.increment-decrement]
1720
[rule.var-naming]
21+
Exclude=["src/os/*.go"]
1822
[rule.var-declaration]
1923
#[rule.package-comments]
2024
[rule.range]
@@ -27,4 +31,5 @@ warningCode = 0
2731
[rule.superfluous-else]
2832
#[rule.unused-parameter]
2933
[rule.unreachable-code]
34+
Exclude=["src/reflect/visiblefields_test.go", "src/reflect/all_test.go"]
3035
#[rule.redefines-builtin-id]

‎src/os/file.go

+1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ func (e *LinkError) Unwrap() error {
310310
return e.Err
311311
}
312312

313+
// OpenFile flag values.
313314
const (
314315
O_RDONLY int = syscall.O_RDONLY
315316
O_WRONLY int = syscall.O_WRONLY

‎src/os/path_unix.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
package os
88

99
const (
10-
PathSeparator = '/' // OS-specific path separator
11-
PathListSeparator = ':' // OS-specific path list separator
10+
PathSeparator = '/' // PathSeparator is the OS-specific path separator
11+
PathListSeparator = ':' // PathListSeparator is the OS-specific path list separator
1212
)
1313

1414
// IsPathSeparator reports whether c is a directory separator character.

‎src/os/path_windows.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
package os
66

77
const (
8-
PathSeparator = '\\' // OS-specific path separator
9-
PathListSeparator = ';' // OS-specific path list separator
8+
PathSeparator = '\\' // PathSeparator is the OS-specific path separator
9+
PathListSeparator = ';' // PathListSeparator is the OS-specific path list separator
1010
)
1111

1212
// IsPathSeparator reports whether c is a directory separator character.

‎src/reflect/value_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ func TestTinyStruct(t *testing.T) {
489489

490490
func TestTinyZero(t *testing.T) {
491491
s := "hello, world"
492-
var sptr *string = &s
492+
sptr := &s
493493
v := ValueOf(&sptr).Elem()
494494
v.Set(Zero(v.Type()))
495495

@@ -535,7 +535,7 @@ func TestTinyAddr(t *testing.T) {
535535
}
536536

537537
func TestTinyNilType(t *testing.T) {
538-
var a any = nil
538+
var a any
539539
typ := TypeOf(a)
540540
if typ != nil {
541541
t.Errorf("Type of any{nil} is not nil")

0 commit comments

Comments
 (0)