mirror of
https://github.com/mgechev/revive.git
synced 2025-02-09 13:37:14 +02:00
This commit is contained in:
parent
3d83403fb8
commit
1c3a15caaa
@ -91,7 +91,7 @@ Example:
|
||||
|
||||
```toml
|
||||
[rule.add-constant]
|
||||
arguments = [{maxLitCount = "3",allowStrs ="\"\"",allowInts="0,1,2",allowFloats="0.0,0.,1.0,1.,2.0,2.","ignoreFuncs": "os.*,fmt.Println,make"}]
|
||||
arguments = [{maxLitCount = "3",allowStrs ="\"\"",allowInts="0,1,2",allowFloats="0.0,0.,1.0,1.,2.0,2.","ignoreFuncs": "os\\.*,fmt\\.Println,make"}]
|
||||
```
|
||||
|
||||
## argument-limit
|
||||
|
@ -13,7 +13,7 @@ func TestAddConstant(t *testing.T) {
|
||||
"allowStrs": "\"\"",
|
||||
"allowInts": "0,1,2",
|
||||
"allowFloats": "0.0,1.0",
|
||||
"ignoreFuncs": "os\\.(CreateFile|WriteFile|Chmod|FindProcess),.Println,ignoredFunc",
|
||||
"ignoreFuncs": "os\\.(CreateFile|WriteFile|Chmod|FindProcess),\\.Println,ignoredFunc",
|
||||
}}
|
||||
|
||||
testRule(t, "add-constant", &rule.AddConstantRule{}, &lint.RuleConfig{
|
||||
|
4
testdata/add-constant.go
vendored
4
testdata/add-constant.go
vendored
@ -24,7 +24,9 @@ func foo(a, b, c, d int) {
|
||||
os.FindProcess(102100) // ignore
|
||||
fmt.Println("test", 12) // ignore
|
||||
fmt.Printf("%d", 100) // MATCH /avoid magic numbers like '100', create a named constant for it/
|
||||
myPrintln("%d", 100) // MATCH /avoid magic numbers like '100', create a named constant for it/
|
||||
ignoredFunc(1000) // ignore
|
||||
ignoredFunc1(1000) // ignore - match regexp too
|
||||
|
||||
println("The result of calling myFunc is: ", ignoredFunc(100)) // ignore
|
||||
println("result is: ", ignoredFunc(notIgnoredFunc(ignoredFunc(100)))) // ignore
|
||||
@ -38,7 +40,7 @@ func myPrintln(s string, num int) {
|
||||
|
||||
}
|
||||
|
||||
func not2ignoredFunc(num int) int {
|
||||
func ignoredFunc1(num int) int {
|
||||
return num
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user