Skip to content
/ hhast Public
forked from hhvm/hhast

Mutable AST library for Hack with linting and code migrations

License

Notifications You must be signed in to change notification settings

alexeyt/hhast

This branch is 40 commits behind hhvm/hhast:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8d6e844 · Jun 22, 2022
Nov 4, 2021
Jun 9, 2022
Nov 15, 2021
Nov 15, 2021
Jun 1, 2022
Jun 22, 2022
Apr 26, 2022
Jun 1, 2022
Nov 30, 2021
May 16, 2022
Jul 5, 2018
Jun 1, 2022
May 12, 2021
Apr 8, 2022
May 16, 2022
Feb 15, 2019
Feb 11, 2020
May 8, 2018
Oct 25, 2021
Jun 6, 2022
Jun 1, 2022
Jun 1, 2022

Repository files navigation

HHAST

Continuous Integration

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

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.

About

Mutable AST library for Hack with linting and code migrations

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Hack 99.9%
  • Other 0.1%