hhvm / hhast
A mutable AST library for Hack with linting and code migrations
Installs: 1 001 909
Dependents: 71
Suggesters: 0
Security: 0
Stars: 67
Watchers: 23
Forks: 42
Open Issues: 40
Language:Hack
Requires
- hhvm: ^4.168.2
- facebook/difflib: ^1.0.0
- facebook/hh-clilib: ^2.5.0rc1
- hhvm/type-assert: ^4.2.2
Requires (Dev)
- facebook/fbexpect: ^2.8.1
- facebook/hack-codegen: ^4.0
- hhvm/hacktest: ^2.3.0
- hhvm/hhvm-autoload: ^2.0.4|^3.0
- dev-main / 4.x-dev
- v4.168.3
- v4.168.2
- v4.166.3
- v4.166.2
- v4.166.1
- v4.166.0
- v4.161.2
- v4.161.1
- v4.161.0
- v4.158.3
- v4.158.2
- v4.158.1
- v4.158.0
- v4.157.0
- v4.156.0
- v4.139.4
- v4.139.3
- v4.139.2
- v4.139.1
- v4.139.0
- v4.135.1
- v4.135.0
- v4.133.0
- v4.127.1
- v4.127.0
- v4.123.1
- v4.123.0
- v4.113.1
- v4.113.0
- v4.103.2
- v4.103.1
- v4.103.0
- v4.102.0
- v4.101.0
- v4.100.0
- v4.95.2
- v4.95.1
- v4.95.0
- v4.94.0
- v4.92.1
- v4.92.0
- v4.91.0
- v4.88.x-dev
- v4.88.1
- v4.88.0
- v4.84.1
- v4.84.0
- v4.82.x-dev
- v4.82.2
- v4.82.1
- v4.82.0
- v4.80.0
- v4.78.2
- v4.78.1
- v4.78.0
- v4.72.4
- v4.72.3
- v4.72.2
- v4.72.1
- v4.72.0
- v4.64.6
- v4.64.5
- v4.64.4
- v4.64.3
- v4.64.2
- v4.64.1
- v4.64.0
- v4.62.0
- v4.53.4
- 4.53.3
- v4.53.2
- v4.53.1
- v4.53.0
- v4.41.2
- v4.41.1
- v4.41.0
- v4.33.9
- v4.33.8
- v4.33.7
- v4.33.6
- v4.33.5
- v4.33.4
- v4.33.3
- v4.33.2
- v4.33.1
- v4.33.0
- v4.29.x-dev
- v4.29.4
- v4.29.3
- v4.29.2
- v4.29.1
- v4.29.0
- v4.25.x-dev
- v4.25.1
- v4.25.0
- v4.21.10
- v4.21.9
- v4.21.8
- v4.21.7
- v4.21.6
- v4.21.5
- v4.21.4
- v4.21.3
- v4.21.2
- v4.21.1
- v4.21.0
- v4.15.x-dev
- v4.15.5
- v4.15.4
- v4.15.3
- 4.15.2
- v4.15.1
- v4.15.0
- v4.14.4
- v4.14.3
- v4.14.2
- v4.14.1
- v4.14.0
- v4.13.x-dev
- v4.13.2
- v4.13.1
- v4.13.0
- v4.12.x-dev
- v4.12.0
- v4.11.0
- v4.8.1
- v4.8.0
- v4.7.1
- v4.7.0
- v4.6.x-dev
- v4.6.3
- v4.6.2
- v4.6.1
- v4.6.0
- v4.5.x-dev
- v4.5.2
- v4.5.1
- v4.5.0
- v4.3.0
- v4.2.1
- v4.2.0
- v4.1.3
- v4.1.2
- v4.1.1
- v4.1.0
- v4.0.5
- v4.0.4
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- v3.30.0
- v3.29.1
- v3.29.0
- v3.28.7
- v3.28.6
- v3.28.5
- v3.28.4
- v3.28.3
- v3.28.2
- v3.28.1
- v3.28.0
- v3.27.4
- v3.27.3
- v3.27.2
- v3.27.1
- v3.27.0
- v3.26.0
- v1.0.1
- v1.0
- v0.6
- v0.5
- v0.4
- v0.3
- v0.2
- v0.1
This package is auto-updated.
Last update: 2024-10-30 02:04:57 UTC
README
HHAST is a toolkit for processing the AST of Hack files.
Abstract syntax trees can be an extremely powerful basis for many kinds of tooling beyond compilers and optimization; HHAST is built on top of Hack's Full Fidelity Parser (FFP), providing a Hack object representation of a mutable AST.
Unlike traditional ASTs, the FFP's AST includes all 'trivia' - such as whitespace and comments - allowing you to fully recreate the file from the AST, or create an updated file after mutating the AST, preserving comments and whitespace.
HHAST has 3 main APIs:
- a low-level library for inspecting and manipulating the FFP AST
- a linting framework, with support for auto-fixing linters
- a migration framework
Linters
Linters are designed for subjective or style changes which do not substantially alter the behavior of the code, and may be rejected on a case-by-case basis. Lint errors can provide a suggested fix, which may be based on an AST mutation, but doesn't have to be.
We've included several linters as a starting point, including:
- don't use await in a loop
- methods should be ->lowerCamelCase(), functions should be under_scored()
- always use braces for control flow
- always use
<<__Override>>
where possible
Linters can be used both interactively, or unattended. Autofixing is not supported unattended, however it will exit with non-zero if there are any lint issues, to ease integration with CI systems.
Editor and IDE Support
HHAST is supported by:
- ALE for Vim 8 and neovim
- atom-ide-hhast for Atom IDE and Nuclide
- vscode-hack for Visual Studio Code
Migrations
- user documentation
- most of the linters developer documentation applies for migrations too
Migrations are for sweeping changes you want to apply across your entire codebase, and are often more complex. Taking this into account, the migration framework has built-in support for multi-step migrations (unlike linters). AST-aware migrations can be a powerful tool for:
- adjusting for changes to the language (for example, the shape changes described below)
- replacing deprecated APIs with new ones
- general clean-up of the codebase
Low-level AST library
See the documentation.
License
HHAST is MIT-licensed.