-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix various linting issues and minor bugs #280
Conversation
assert/cmp/compare.go
Outdated
//nolint:errorlint // unwrapping is not appropriate here | ||
// unwrapping is not appropriate here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL looks like different versions of the linters disagree. Let me add nolintlint
to the ignore list;
assert/cmp/compare.go:252:14: type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)
if _, ok := err.(causer); ok {
^
65d6780
to
6d6c58c
Compare
Current versions of this linter default to no allowing third-party dependencies by default (only stdlib and golang.org/x/sys). As there's currently no configuration set to prevent a specific import, this results in some imports being flagged; fs/manifest_test.go:11:2: import 'github.com/google/go-cmp/cmp' is not allowed from list 'Main' (depguard) "github.com/google/go-cmp/cmp" ^ assert/assert.go:96:2: import 'github.com/google/go-cmp/cmp' is not allowed from list 'Main' (depguard) gocmp "github.com/google/go-cmp/cmp" ^ assert/assert_test.go:8:2: import 'github.com/google/go-cmp/cmp' is not allowed from list 'Main' (depguard) gocmp "github.com/google/go-cmp/cmp" ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
The nolintlint linter considers the `nolint` to be redundant; assert/cmp/compare.go:251:2: directive `//nolint:errorlint // unwrapping is not appropriate here` is unused for linter "errorlint" (nolintlint) //nolint:errorlint // unwrapping is not appropriate here ^ But depending on the go version, it may trigger a warning: assert/cmp/compare.go:252:14: type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint) if _, ok := err.(causer); ok { ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
assert/assert_test.go:108:3: empty-block: this block is empty, you can remove it (revive) for range []int{1, 2, 3, 4} { } Signed-off-by: Sebastiaan van Stijn <[email protected]>
6d6c58c
to
d65bc1e
Compare
internal/source/source.go:75:2: return both the `nil` error and invalid value: use a sentinel error instead (nilnil) return nil, nil ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
"cap" is now a builtin: internal/source/source_test.go:50:2: redefines-builtin-id: redefinition of the built-in function cap (revive) cap := &capture{} ^ internal/source/source_test.go:73:2: redefines-builtin-id: redefinition of the built-in function cap (revive) cap := &capture{} ^ internal/source/source_test.go:86:2: redefines-builtin-id: redefinition of the built-in function cap (revive) cap := &capture{} ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
fs/report_test.go:187:19: unused-parameter: parameter 'b' seems to be unused, consider removing or renaming it as _ (revive) matcher := func(b []byte) CompareResult { ^ fs/report_test.go:196:19: unused-parameter: parameter 'b' seems to be unused, consider removing or renaming it as _ (revive) matcher := func(b []byte) CompareResult { ^ fs/report.go:107:46: printf: non-constant format string in call to gotest.tools/v3/fs.existenceProblem (govet) p = append(p, existenceProblem("content", r.FailureMessage())) ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
assert/assert_test.go:249:12: unused-parameter: parameter 'b' seems to be unused, consider removing or renaming it as _ (revive) f := func(b bool) {} ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
Current versions of govet check for printf functions called with a format string, but no arguments. This results in linting errors: fs/report.go:107:46: printf: non-constant format string in call to gotest.tools/v3/fs.existenceProblem (govet) p = append(p, existenceProblem("content", r.FailureMessage())) ^ This patch changes existenceProblem to use format.Message, which is used elsewhere for similar situations. Signed-off-by: Sebastiaan van Stijn <[email protected]>
poll/example_test.go:38:16: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive) check := func(t poll.LogT) poll.Result { ^ poll/poll_test.go:21:21: unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive) func (t *fakeT) Log(args ...interface{}) {} ^ poll/poll_test.go:23:22: unused-parameter: parameter 'format' seems to be unused, consider removing or renaming it as _ (revive) func (t *fakeT) Logf(format string, args ...interface{}) {} ^ poll/poll_test.go:28:16: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive) check := func(t LogT) Result { ^ poll/poll.go:154:18: printf: non-constant format string in call to gotest.tools/v3/poll.Continue (govet) return Continue(buf.String()) ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
assert/opt/opt_test.go:254:20: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive) func TestPathDebug(t *testing.T) { ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
x/subtest/example_test.go:47:23: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive) func startFakeService(t subtest.TestContext) string { ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
poll/poll.go:154:18: printf: non-constant format string in call to gotest.tools/v3/poll.Continue (govet) return Continue(buf.String()) ^ Signed-off-by: Sebastiaan van Stijn <[email protected]>
d65bc1e
to
d21c522
Compare
|
||
func (t *fakeT) Log(args ...interface{}) {} | ||
func (t *fakeT) Log(...interface{}) {} | ||
|
||
func (t *fakeT) Logf(format string, args ...interface{}) {} | ||
func (t *fakeT) Logf(string, ...interface{}) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you coule use any
instead of interface{}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept interface{}
for now, so that we didn't have to raise the go version in go.mod
;
Line 3 in 631f6c8
go 1.17 |
(any
would require go1.18 as minimum; https://go.dev/ref/spec#Go_1.18)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know 😬 but Go 1.18 is now not only old, but no longer supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, more than aware; I also know that it's not uncommon for companies to maintain an (internal) LTS version of older Go versions. Not all of those will be visible publicly on GitHub. (e.g. I know Google for a long time required compatibility with go1.13 for some of their systems - they maintained their own version for that).
@@ -50,8 +50,8 @@ func errProblem(reason string, err error) problem { | |||
return problem(fmt.Sprintf("%s: %s", reason, err)) | |||
} | |||
|
|||
func existenceProblem(filename, reason string, args ...interface{}) problem { | |||
return problem(filename + ": " + fmt.Sprintf(reason, args...)) | |||
func existenceProblem(filename string, msgAndArgs ...interface{}) problem { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you coule use ...any
instead of ...interface{}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
We should update the Go minimum version sometime soon.
Yes, if there's a need to bump, that's probably fine. I tried to avoid it if there's no strict / important reason, knowing that gotest.tools is a test-dependency, and (library) projects may want to continue support for old Go versions, therefore running tests against those, so it's worth trying to keep the requirements as low as reasonably possible. |
See individual commits for details.