Ruleguard by example
Ruleguard is a tool that makes it easy to write custom Go static analysis.
Ruleguard by example is a hands-on introduction that helps you to learn how to write and run custom linting rules.
- Hello world - a minimal working example to start out journey
- Submatches - exploring named and unnamed pattern submatch variables
- Multi-rule groups - putting several rules inside one function, making them short-circuit
- Multi-pattern rules - putting several patterns into a single rule
- Multi-statement patterns - putting several statements into a single pattern
- Autofixable rules - using
Suggest()
to enable quickfix actions
- Optional submatches - usign
*
variable modifier to match variadic or optional parts of the pattern
- Filters - using
Where()
to reject the unwanted matches
- Type filters - applying type-based constraints to your rules
- Type patterns - mastering the advanced type pattern matching techniques
- External types - using
Import()
to bind qualified type names
- Underlying types - understanding the underlying types in Go and how can we handle them in the Ruleguard
- Node predicates - asserting the submatch nodes AST types
- File predicates - applying file-scoped filters
- Text filters - matching "literal" variables (by their name) and more
- Nested AST filters - matching an AST pattern inside other AST
- Constexpr evaluation - writing filters based on the expression values
- Custom locations - using
At()
to adjust the match location
- Custom filters - writing own filters for the
Where()
clause
- Matching comments - finding issues inside code comments
- Go version checks - limiting the rules to the specified Go version
- Deadcode detection - handling the code reachability
- Local functions - reusing filter expressions in multiple
Where()
clauses