Skip to content

Commit

Permalink
Add print and println to default exclusions list (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashanbrown authored May 10, 2021
1 parent 621d0db commit f30240a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ forbidigo is a Go static analysis tool to forbidigo use of particular identifier

forbidigo [flags...] patterns... -- packages...

If no patterns are specified, the default pattern of `^fmt\.Print.*$` is used to eliminate debug statememts. By default,
If no patterns are specified, the default pattern of `^(fmt\.Print.*|print|println)$` is used to eliminate debug statements. By default,
functions (and whole files), that are identifies as Godoc examples (https://blog.golang.org/examples) are excluded from
checking.

Expand Down
2 changes: 2 additions & 0 deletions examples/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import "fmt"
func Foo() {
fmt.Println("here I am")
fmt.Printf("this is ok") //permit:fmt.Printf // this is ok
print("not ok")
println("also not ok")
}
4 changes: 3 additions & 1 deletion examples/expected_results.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
use of `fmt.Println` forbidden by pattern `^fmt\.Print(|f|ln)$` at CURDIR/examples/example.go:6:2
use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` at CURDIR/examples/example.go:6:2
use of `print` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` at CURDIR/examples/example.go:8:2
use of `println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` at CURDIR/examples/example.go:9:2
2 changes: 1 addition & 1 deletion forbidigo/forbidigo.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Linter struct {
}

func DefaultPatterns() []string {
return []string{`^fmt\.Print(|f|ln)$`}
return []string{`^(fmt\.Print(|f|ln)|print|println)$`}
}

//go:generate go-options config
Expand Down

0 comments on commit f30240a

Please sign in to comment.