-
Notifications
You must be signed in to change notification settings - Fork 285
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
strconv.ParseInt(myID, 10, 32) --> add-constant: avoid magic numbers like '10' #784
Comments
Hi @guettli, thanks for filling the issue. strconv.ParseInt(myID, asDecimal, of32bitsSize) We could wait some feedback from other users to see if there is some kind of consensus on the subject (and, if necessary, in the way to implement a solution) |
@chavacava until you got enough feedback from the community: What is the best way to silence this particular check? |
For this particular rule you can:
(you can find an example of the rule's configuration here) Side note: I do not activate this rule in my setup mainly because its added value does not worth the configuration effort. |
@chavacava sorry, that I need to ask you again. I tried to ignore it via
But it fails. Code:
The line gets ignored if I add 10 and 32 to allowInts. |
@guettli I will check from my side. |
Hi @guettli, sorry for the late response. Source code: package main
import (
"strconv"
"strings"
)
func test() {
deviceID, err := strconv.ParseInt(strings.TrimPrefix(node.Spec.ProviderID, providerPrefix), 10, 32)
} Configuration: confidence = 0.1
enableAllRules = false
severity = "error"
errorCode = 1
warningCode = 1
[rule.add-constant]
arguments = [{"ignoreFuncs"= "strconv\\.ParseInt"}] Running the linter produces, as expected, no output:
If I modify the configuration to do not ignore calls to confidence = 0.1
enableAllRules = false
severity = "error"
errorCode = 1
warningCode = 1
[rule.add-constant] The linter reports the issue:
You are using |
Think good design - keep base + allow do what exactly required for some people in custom config for rule. While we knows at revive level package and name of function or package+obj+method (as in unhandled-error rule) we can add something like this:
Where are several cases where hard-coded numbers and strings are more readable and understandable than moved to constants. But it's not by default |
Closing for the moment. If the rule is too noisy (too much false positives) in your codebases, I recommend to deactivate it. |
Is your feature request related to a problem? Please describe.
I get this warning:
I see these ways to handle this:
All these solutions are extra work and not nice.
Describe the solution you'd like
I think the above warning should not appear by default.
Describe alternatives you've considered
I can solve this on my own, but a solution for everybody would be better.
Additional context
I use:
The text was updated successfully, but these errors were encountered: