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.

  1. Hello world - a minimal working example to start out journey
  2. Submatches - exploring named and unnamed pattern submatch variables
  3. Multi-rule groups - putting several rules inside one function, making them short-circuit
  4. Multi-pattern rules - putting several patterns into a single rule
  5. Multi-statement patterns - putting several statements into a single pattern
  6. Autofixable rules - using Suggest() to enable quickfix actions
  7. Optional submatches - usign * variable modifier to match variadic or optional parts of the pattern
  8. Filters - using Where() to reject the unwanted matches
  9. Type filters - applying type-based constraints to your rules
  10. Type patterns - mastering the advanced type pattern matching techniques
  11. External types - using Import() to bind qualified type names
  12. Underlying types - understanding the underlying types in Go and how can we handle them in the Ruleguard
  13. Node predicates - asserting the submatch nodes AST types
  14. File predicates - applying file-scoped filters
  15. Text filters - matching "literal" variables (by their name) and more
  16. Constexpr evaluation - writing filters based on the expression values
  17. Custom locations - using At() to adjust the match location
  18. Custom filters - writing own filters for the Where() clause
  19. Matching comments - finding issues inside code comments
  20. Go version checks - limiting the rules to the specified Go version
  21. Deadcode detection - handling the code reachability
  22. Local functions - reusing filter expressions in multiple Where() clauses