Skip to content
Check that regular expressions in global `MustCompile` calls are valid.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
testdata
.gitignore
.travis.yml
LICENSE
README.md
check_regex.go
check_regex_test.go
go.mod
main.go

README.md

gocheckregex

Build Status Codecov Go Report Card

Check that regular expressions in global MustCompile calls are valid.

Why

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.

Install

go get 4d63.com/gocheckregex

Usage

gocheckregex
gocheckregex ./...
gocheckregex [path] [path] [path] [etc]

Note: Paths are only inspected recursively if the Go /... recursive path suffix is appended to the path.

Limitations

  • Does not pickup on regexp usage if package regexp is aliased.
  • Only looks at MustCompile calls that's argument is a string literal.
You can’t perform that action at this time.