-
Notifications
You must be signed in to change notification settings - Fork 61
fix: linter errors #276
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: linter errors #276
Changes from all commits
3952231
fd09913
fe8559d
76e9807
76978ba
dc1a6ff
e26fad1
5923e1a
4d8ac23
dca09c5
881f312
122c3c4
444110c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,7 +206,7 @@ func Parser() *flags.Parser { | |
| name = string(opt.ShortName) | ||
| } | ||
| desc, ok := c.optDescs[name] | ||
| if !(c.optDescs == nil || ok) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure how Gustavo feels about this linter. In general I would refrain from re-writing boolean conditions by negating them. While it is true that the result is the same, I think the readability is not the same, and IMO we should respect the author's decision to write it this same if it is more clear / more uniform.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point and I am on the fence on this one. On one hand, I agree that we might have cases where a form could be more readable or better convey the author's intention. So being forced by the linter might be impractical. On the other hand, we have more than 150 occurrences of WDYT?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In these two cases I agree as well, but I find it stylistic more than anything else. I can see how someone prefers the negation. Anyway, no strong opinion on my side, we can try it out and remove if we are not happy.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, Alberto has a good point, but this particular case seems like the linter did a good job. The replacement is more readable than the original, and it actually aligns with similar states before and after this one. So +1 on the linter result. |
||
| if c.optDescs != nil && !ok { | ||
| panicf("%s missing description for %s", c.name, name) | ||
| } | ||
| lintDesc(c.name, name, desc, opt.Description) | ||
|
|
@@ -261,7 +261,7 @@ func Parser() *flags.Parser { | |
| name = string(opt.ShortName) | ||
| } | ||
| desc, ok := c.optDescs[name] | ||
| if !(c.optDescs == nil || ok) { | ||
| if c.optDescs != nil && !ok { | ||
| panicf("%s missing description for %s", c.name, name) | ||
| } | ||
| lintDesc(c.name, name, desc, opt.Description) | ||
|
|
@@ -345,7 +345,7 @@ func run() error { | |
| sug := "chisel help" | ||
| if len(xtra) > 0 { | ||
| sub = xtra[0] | ||
| if x := parser.Command.Active; x != nil && x.Name != "help" { | ||
| if x := parser.Active; x != nil && x.Name != "help" { | ||
| sug = "chisel help " + x.Name | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,7 +125,7 @@ func (r *Release) Content() []byte { | |
| digests := bytes.Buffer{} | ||
| for _, item := range r.Items { | ||
| content := item.Content() | ||
| digests.WriteString(fmt.Sprintf(" %s %d %s\n", makeSha256(content), len(content), item.Path())) | ||
| fmt.Fprintf(&digests, " %s %d %s\n", makeSha256(content), len(content), item.Path()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting that this is automatic, how was this suggested? I checked the API and it appears to be the same minus a possibly different error returned, but we are not using it anyway...
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is rule I also agree that it is a relatively safe change since we are not doing anything with the returned values.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, let's keep it then |
||
| } | ||
| content := fmt.Sprintf(string(testutil.Reindent(` | ||
| Origin: Ubuntu | ||
|
|
||
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.
Some of these like ST1012 or ST1005 are too opinionated for my taste. Why not disable them in general as you had done before? I don't want to write a new error that is not
errSomethingand see a linter error, while the existing ones work. If we think the rule is invalid or too opinionated then we should block it directly, not only allow current usages.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.
My goal here was to:
ST1012 enforces the naming convention recommended in https://go.dev/wiki/Errors#naming, so it does not seem too opinionated to me (at least not more than other idiomatic rules of the language). I even think
preferNonecould be renamed to respect the rule.Regarding ST1005: we are already respecting the rule (also implicitly respected in examples of PL007), and this linter rule should help us catch any deviation. I added an exception for
cmd/chisel/*.gobecause the CLI prints errors that require final punctuation to be nice messages to users, so I think the exception is fine here (I am not 100% happy about the granularity here, but this is a limitation due to not using inline comments for exceptions).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.
If you think current exceptions could be renamed then okay and you think the rule is beneficial. What I wouldn't like happening is to add more exceptions to the rule in the future.
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 will add a TODO to mention no exception should be added for these rules and existing ones should be removed when possible.
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.
Why not fixing these right now? It's just two cases.
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 expected the renaming of these errors to be a bit controversial because the unexported one was very carefully named and the other one is exported. So I did not want this to block the bulk of the cleaning. I prepared #293 to address it.