go-ruleguard
Overview
analysis-based Go linter that runs dynamically loaded rules.
You write the rules, ruleguard
checks whether they are satisfied.
ruleguard
has some similarities with GitHub CodeQL, but only focuses on Go code queries.
Features:
- Custom linting rules without re-compilation and Go plugins.
- Diagnostics are written in a declarative way.
- Quickfix actions support.
- Powerful match filtering features, like expression type pattern matching.
ruleguard
comes with rules.go file that can be used as a foundation to write your own rules file.
It can also be easily embedded into other static analyzers. go-critic can be used as an example.
Quick start
To install ruleguard
binary under your $(go env GOPATH)/bin
:
$ go get -v -u github.com/quasilyte/go-ruleguard/...
If $GOPATH/bin
is under your system $PATH
, ruleguard
command should be available after that.
$ ruleguard -help
ruleguard: execute dynamic gogrep-based rules
Usage: ruleguard [-flag] [package]
Flags:
-rules string
path to a rules.go file
-e string
execute a single rule from a given string
-fix
apply all suggested fixes
-c int
display offending line with this many lines of context (default -1)
-json
emit JSON output
Create a test example.rules.go
file:
// +build ignore
package gorules
import "github.com/quasilyte/go-ruleguard/dsl/fluent"
func _(m fluent.Matcher) {
m.Match(`$x