Check that regular expressions in global MustCompile
calls are valid.
It's a common practice to compile regexs on application start by using the regexp.MustCompile
function to build the regular expression and store it in a global variable. The MustCompile
function will panic then on startup if the regular expression can't be compiled. It would be great if we found out sooner without running the application if the regex we've written is invalid.
go get 4d63.com/gocheckregex
gocheckregex
gocheckregex ./...
gocheckregex [path] [path] [path] [etc]
Note: Paths are only inspected recursively if the Go /...
recursive path suffix is appended to the path.
- Does not pickup on regexp usage if package
regexp
is aliased. - Only looks at MustCompile calls that's argument is a string literal.