Skip to content

Commit

Permalink
Lint: lint and fix src/{os,reflect} (#4228)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dkegel-fastly committed Apr 22, 2024
1 parent 1154212 commit 3d433fe
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
10 changes: 6 additions & 4 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,9 @@ deb: build/release
endif

lint:
# Only run on compiler dir for now, expand as we clean up other dirs
# This obviously won't scale, but it's a start, and it's fast
go run github.com/mgechev/revive --version
go run github.com/mgechev/revive --config revive.toml compiler/...
go run github.com/mgechev/revive -version
# TODO: lint more directories!
# revive.toml isn't flexible enough to filter out just one kind of error from a checker, so do it with grep here.
# Can't use grep with friendly formatter. Plain output isn't too bad, though.
# Use 'grep .' to get rid of stray blank line
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}'
2 changes: 2 additions & 0 deletions internal/tools/tools.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build tools

// Install linter versions specified in go.mod
// See https://marcofranssen.nl/manage-go-tools-via-go-modules for idom
package tools
Expand Down
5 changes: 5 additions & 0 deletions revive.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ warningCode = 0

# Enable these as we fix them
[rule.blank-imports]
Exclude=["src/os/file_other.go"]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
Exclude=["**/*_test.go"]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.exported]
Exclude=["src/reflect/*.go"]
[rule.increment-decrement]
[rule.var-naming]
Exclude=["src/os/*.go"]
[rule.var-declaration]
#[rule.package-comments]
[rule.range]
Expand All @@ -27,4 +31,5 @@ warningCode = 0
[rule.superfluous-else]
#[rule.unused-parameter]
[rule.unreachable-code]
Exclude=["src/reflect/visiblefields_test.go", "src/reflect/all_test.go"]
#[rule.redefines-builtin-id]
1 change: 1 addition & 0 deletions src/os/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func (e *LinkError) Unwrap() error {
return e.Err
}

// OpenFile flag values.
const (
O_RDONLY int = syscall.O_RDONLY
O_WRONLY int = syscall.O_WRONLY
Expand Down
4 changes: 2 additions & 2 deletions src/os/path_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
package os

const (
PathSeparator = '/' // OS-specific path separator
PathListSeparator = ':' // OS-specific path list separator
PathSeparator = '/' // PathSeparator is the OS-specific path separator
PathListSeparator = ':' // PathListSeparator is the OS-specific path list separator
)

// IsPathSeparator reports whether c is a directory separator character.
Expand Down
4 changes: 2 additions & 2 deletions src/os/path_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
package os

const (
PathSeparator = '\\' // OS-specific path separator
PathListSeparator = ';' // OS-specific path list separator
PathSeparator = '\\' // PathSeparator is the OS-specific path separator
PathListSeparator = ';' // PathListSeparator is the OS-specific path list separator
)

// IsPathSeparator reports whether c is a directory separator character.
Expand Down
4 changes: 2 additions & 2 deletions src/reflect/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func TestTinyStruct(t *testing.T) {

func TestTinyZero(t *testing.T) {
s := "hello, world"
var sptr *string = &s
sptr := &s
v := ValueOf(&sptr).Elem()
v.Set(Zero(v.Type()))

Expand Down Expand Up @@ -535,7 +535,7 @@ func TestTinyAddr(t *testing.T) {
}

func TestTinyNilType(t *testing.T) {
var a any = nil
var a any
typ := TypeOf(a)
if typ != nil {
t.Errorf("Type of any{nil} is not nil")
Expand Down

0 comments on commit 3d433fe

Please sign in to comment.