Skip to content

Commit

Permalink
fix #759 [rule.add-constant] change 'ignoreFuncs' expressions in docu…
Browse files Browse the repository at this point in the history
…mentation and test (#760)
  • Loading branch information
rawen17 authored Oct 15, 2022
1 parent 3d83403 commit 1c3a15c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion RULES_DESCRIPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/add-constant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 3 additions & 1 deletion testdata/add-constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,7 +40,7 @@ func myPrintln(s string, num int) {

}

func not2ignoredFunc(num int) int {
func ignoredFunc1(num int) int {
return num
}

Expand Down

0 comments on commit 1c3a15c

Please sign in to comment.