-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
chore: explicit revive rules #8290
base: main
Are you sure you want to change the base?
Conversation
0e5f797
to
40f4c06
Compare
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.
While it looks good to me, I cannot accept it alone since it affects the whole project. I like this change as I prefer less nesting, but this depends on the developer's preference. What do you think? @aquasecurity/trivy
One thing to note is that early return may not be equivalent to if-else. For example, in the following case, pkg
is scoped in the if-else
statement.
if pkg, ok := pkgs[vuln.PkgID+vuln.PkgPath]; !ok {
continue
} else {
r.Results[i].Vulnerabilities[j].PkgIdentifier = pkg.Identifier
}
However, pkg
will be alive outside the if
scope in this case.
pkg, ok := pkgs[vuln.PkgID+vuln.PkgPath]
if !ok {
continue
}
r.Results[i].Vulnerabilities[j].PkgIdentifier = pkg.Identifier
As far as I could review, none of the changes seemed to be affected by this change in scope, but in some cases, it may need to disable the linter with nolint
. Just sharing.
There is a preserveScope argument to normally adress your concern except if I'm missing the point |
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.
LGTM
pkg/rpc/convert.go
Outdated
data, err := structpb.NewValue(res.Data) | ||
if err != nil { | ||
|
||
} else { |
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.
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 also noticed and accepted the change as the function doesn't return an error. But yes, you're right. I forgot about the idea of showing warnings. We should warn it.
magefiles/magefile.go
Outdated
if ver, err := sh.Output("git", "describe", "--tags", "--always"); err != nil { | ||
ver, err := sh.Output("git", "describe", "--tags", "--always") | ||
if err != nil { |
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 actually prefer inlining if conditions to reduce nesting and lines of code, however this is subjective. But as @knqyf263 pointed out, (not this particular instance) it may lead to subtle errors. And as you mentioned, to suppress them either we'd have to add preserveScope
argument or /nolint
.
Based on that is it still worth to add this rule?
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 prefer not to reuse the variable name inside if-else (for me it is more readable code)
e.g.:
pkg := Package{name: "foo"}
if p, ok := pkgs["bar"]; ok{ // for this case i don't use `pkg`. I will use `p`, `foundPkg`, etc.
...
}
so in my case these changes will not lead to consequences.
but this is just my opinion
40f4c06
to
58b5b7a
Compare
Let’s narrow this to list rules and disable those not already applied. so each rule can be discussed and enabled one at a time. |
Signed-off-by: Matthieu MOREL <[email protected]>
58b5b7a
to
26048b0
Compare
It's nice! Thanks for sharing. |
Description
This list all default rules and a bit more.
It keeps disabled the rules that are not yet applied