Skip to content
Mutable AST library for Hack with linting and code migrations
Branch: master
Clone or download
fredemmott Minor refactoring of marker interface handling
- key by interface rather than class for clarity. Map to old format for
efficiency
- remove explicit IControlStatement for ILoopStatements (which extends
IControlStatement)

refs #167
Latest commit 9275b41 May 2, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode enable vscode hhast support whenever operating in this repo Jul 9, 2018
bin exec update-codegen directly, not with hhvm Mar 11, 2019
codegen Minor refactoring of marker interface handling May 2, 2019
docs Update link to TConfigFile Feb 20, 2019
src
tests Lambda and lval (#166) May 1, 2019
.LICENSE_HEADER.hh.txt Add autofixing linter for license headers (#96) Jul 5, 2018
.gitattributes add linguist language override (#159) Apr 23, 2019
.gitignore Make the LSP test framework less flakey Aug 22, 2018
.hhconfig Remove static locals Mar 26, 2019
.travis.sh remove composer.lock when testing against nightlies Apr 9, 2019
.travis.yml
CODE_OF_CONDUCT.md add CODE_OF_CONDUCT.md Feb 15, 2019
CONTRIBUTING.md Fix generated @return docblock (#143) Dec 3, 2018
LICENSE Relicense to MIT May 8, 2018
README.md document editor and IDE integrations Aug 7, 2018
composer.json Require 4.3 Apr 30, 2019
composer.lock Require 4.3 Apr 30, 2019
hh_autoload.json Use dev-master of hhvm-autoload Sep 16, 2017
hhast-lint.json Add autofixing linter for license headers (#96) Jul 5, 2018

README.md

HHAST

Build Status

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

screenshot of lint errors

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

screenshot of lint errors in VSCode

HHAST is supported by:

Migrations

user documentation

screenshot of a migration

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.

You can’t perform that action at this time.