BaseLinter
: base class of all linters, and independent from the ASTBaseASTLinter
: base class for linters that operate on AST nodes; you shouldn't usually extend this directly; you probably want eitherASTLinter
orAutoFixingASTLinter
instead. You'll need to extend this if you want to use the AST to detect an issue, but an approach other than AST manipulation to automatically fix them (e.g. shelling out tohh_client --refactor
)ASTLinter
: base class for linters that use the AST to detect issues, but don't have an auto-fixAutoFixingLinter
: an interface that specifies that a linter is able to fix its' own lint problemsAutoFixingASTLinter
: a subclass ofASTLinter
which implementsAutoFixingLinter
, for when your auto-fix is based on an AST mutationFunctionNamingLinterTrait
: helper forASTLinter
subclasses
LintError
: base of all linter errors. It allows you to provide a description, and blame text (usually code)FixableLintError
: interface for lint errors that might be fixable. It specifies how to fix them, and a way to describe the fix. The error is actually fixed by passing the error to the linters' fix methodASTLintError
: subclass ofLintError
for linters that derive fromBaseASTLintError
, but notAutoFixingASTLintError
FixableASTLintError
: subclass ofASTLintError
for linters that are a subclass ofAutoFixingASTLinter
The best way is to read through the existing linters to get a feel for what's supported, and what works well.
It's best to heavily use unit tests when working on linters; once your tests pass and you're ready to get started, add it to your hhast-lint.json
.
- install
jq
or another JSON prettifier, and examine files containing AST structures you're interested in withhh_parse --full-fidelity-json $file | jq
- use an IDE with autocompletion; there are far too many AST node types for memorizing the APIs to be practical
- include various combinations of leading and trailing whitespace and comments in your unit tests for auto-fixing linters
- if you use
hackfmt
and aren't planning to send a pull request toHHAST
, you might want to ignore whitespace in auto-fixing AST linters: getting whitespace correct is generally more consuming than the logical change itself. Instead, you could ask your users to rungit show | hackfmt --diff
, or add a non-AST autofixing linter to do that instead