Coder Social home page Coder Social logo

hhast's Introduction

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

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.

hhast's People

Contributors

fredemmott avatar jjergus avatar lexidor avatar bradleyhd avatar wlin53 avatar ryangreenberg avatar aloiret avatar ssandler avatar azjezz avatar johanoskarsson avatar aloiret-ed avatar muglug avatar joecheuk avatar yucombinator avatar vsiles avatar traviscrawford avatar tj09 avatar simonwelsh avatar pranayagarwal avatar matt-schellhas avatar kmeht avatar viratyosin avatar ianhoffman avatar kingkrausel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.