Conversation
a79a73e to
d3fc1e6
Compare
|
I think it's a good linter and it can find some real issues, but I propose to fix issues first to avoid confusion from other contributors. I can help with that. |
|
I agree that PR #3106 got quite messy, but I think this PR does it better. Adding the linter is jus |
2d006bc to
b8acc96
Compare
There was a problem hiding this comment.
The linter issues all seem to be resolved, I would appreciate a review @binjip978 @rminnich @RiSKeD
b8acc96 to
310a639
Compare
|
After we finish this, I propose adding |
310a639 to
c4b3b41
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3111 +/- ##
==========================================
- Coverage 60.67% 60.53% -0.15%
==========================================
Files 598 598
Lines 39890 39888 -2
==========================================
- Hits 24204 24145 -59
- Misses 15686 15743 +57
Flags with carried forward coverage won't be shown. Click here to find out more.
|
RiSKeD
left a comment
There was a problem hiding this comment.
LGTM!
IMO it makes sense to leave some nolint cases behind for functions we don't want to refactor right now, as we get the benefits of this linter for any new commits 👍
c4b3b41 to
f1b58ad
Compare
f1b58ad to
72a21cf
Compare
pkg/netstat/format.go
Outdated
|
|
||
| if pnote.PID == 0 { | ||
| s.WriteString("-") | ||
| if _, err = s.WriteString("-"); err != nil { |
There was a problem hiding this comment.
It's not clear to me how WriteString can fail here?
// WriteString appends the contents of s to b's buffer.
// It returns the length of s and a nil error.
func (b *Builder) WriteString(s string) (int, error) {
b.copyCheck()
b.buf = append(b.buf, s...)
return len(s), nil
}I would rather have something like _, _ = s.WriteString("-")
There was a problem hiding this comment.
This sounds reasonable. This could also be a good solution for the flag parsing issues @rminnich stated.
a8274ba to
99a993e
Compare
rminnich
left a comment
There was a problem hiding this comment.
I would want to know if we can not replace all those ugly no lint directives with _ parameters, to start.
| return nil | ||
| } | ||
|
|
||
| //nolint:unparam |
There was a problem hiding this comment.
rather than the no lint: thing, you ought to be able to say
func reply(_ io.Writer, r byte) {...}
If golangci-lint does not understand this, then it does not understand go.
| // hardcoding seems not be a good idea since we may need this function for | ||
| // future testing | ||
| // | ||
| //nolint:unparam |
There was a problem hiding this comment.
Again, the common way to indicate an unused parameter is
func f(_ int, something int)
does golangci-lint not understand this?
I really don't like these no lint: things everywhere. It means, when code changes, people also need to understand to change the nolint, and they will forget. And then we'll have a bogus no lint directive. It's why these extraterritorial things are such a problem.
Does golangci-lint understand _ parameters? If not, it should.
There was a problem hiding this comment.
Just confirmed: _ the param and golangci-lint will not complain.
remove this nolint: there is a Go-standard way to do this.
| return int(clktck), nil | ||
| } | ||
|
|
||
| //nolint:unparam |
There was a problem hiding this comment.
and if we have all these unused parameters, why don't we just fix the code?
| // TODO: I am not sure what the status block is passed here and if it is really | ||
| // necessary, this should be audited | ||
| // | ||
| //nolint:unparam |
There was a problem hiding this comment.
so we have code we don't understand that we're patching up with no lint directives? Kinda nasty?
| @@ -106,11 +106,7 @@ func (c cmd) Modify(ns Namespace, b *Builder) error { | |||
| } | |||
| return ns.Import(host, remotepath, mountpoint, c.flag) | |||
There was a problem hiding this comment.
This looks good. This one change is a case for making this into more than one PR. It's SO BIT, it's exhausting to read.
| } | ||
|
|
||
| s.WriteString(pnote.Name) | ||
| _, _ = s.WriteString(pnote.Name) |
There was a problem hiding this comment.
this is just so ugly, but I guess we have no choice, but yuck.
|
So far, golangci-lint mainly seems to make code unnecessarily ugly, and seems to be a way to avoid fixing things ... |
rminnich
left a comment
There was a problem hiding this comment.
every single nolint: here is making things worse. Let's fix things, in a series of PR, and we can even have a golangci-lint test that is not required (at first) to show us what we need to continue to fix.
I really dislike things like nolint: in code. Over time, they get stale and cause trouble.
| // disable the noparam linter to fail because we always return nil. | ||
| // | ||
| //nolint:unparam | ||
| func (c *cmd) run() error { |
There was a problem hiding this comment.
This is the wrong fix.
What should be done is to use errors.Join
so this command and the nolint: actually make things worse.
This is why I am so concerned about this PR. It is guiding people to do the wrong thing.
| // TODO: rework 'what' parameter, maybe remove it? | ||
| // | ||
| //nolint:unparam | ||
| func getArg(b *bufio.Reader, what string) string { |
There was a problem hiding this comment.
OK, I just now tested this change:
-func getArg(b *bufio.Reader, what string) string {
+func getArg(b *bufio.Reader, _ string) string {
rminnich@sidecore:~/go/src/github.com/u-root/u-root$ golangci-lint run cmds/exp/rush/parse.go
rminnich@sidecore:~/go/src/github.com/u-root/u-root$
golangci-lint is fine with _ parameters.
So, the fix in the PR is the wrong fix. Adding the nolint: makes things worse.
Either remove what, which is the better solution; or make it _ string.
I would bet that just about every nolint: in this PR could be done a better way.
|
|
||
| // TODO: refactor to return error instead of logger.Fatalf | ||
| // | ||
| //nolint:unparam |
There was a problem hiding this comment.
If you do a TODO, it will never get done. Let's fix this right.
| // hardcoding seems not be a good idea since we may need this function for | ||
| // future testing | ||
| // | ||
| //nolint:unparam |
There was a problem hiding this comment.
Just confirmed: _ the param and golangci-lint will not complain.
remove this nolint: there is a Go-standard way to do this.
add linter option 'unparam' to ci Signed-off-by: leongross <leon.gross@9elements.com>
* fix unparam issues, remove unused error returns * fix changed tests when no error is returned anymore * add TODOs and //nolint:unparam tags for future rework/refactoring Signed-off-by: leongross <leon.gross@9elements.com>
While working on PR #3109 I ran into the issue, that a function was changed in such a way, that the signature was still taking an unused parameter. The Github CI did not pick this up. We should add detection to enforce a cleaner codebase.