1
0
mirror of https://github.com/mgechev/revive.git synced 2025-02-09 13:37:14 +02:00

fix #759 [rule.add-constant] change 'ignoreFuncs' expressions in documentation and test (#760)

This commit is contained in:
Buyanov Vladimir 2022-10-15 12:24:32 +03:00 committed by GitHub
parent 3d83403fb8
commit 1c3a15caaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View File

@ -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

View File

@ -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{

View File

@ -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
}