HerringtonDarkholme 292a2a3285 [chore] add pre-commit
2022-08-06 20:56:00 -04:00
2022-08-06 00:45:07 -04:00
2022-08-06 20:12:21 -04:00
2022-08-03 00:07:02 -04:00
2022-08-06 18:10:49 -04:00
2022-07-01 16:04:47 -04:00
2022-08-06 20:56:00 -04:00
2022-08-06 00:43:55 -04:00
2022-07-31 01:31:23 -04:00

ASTGrep

A fast and easy tool for code searching, linting, rewriting at large scale.

Introduction

ASTGrep is a lightning fast and user-friendly tool that performs static analysis and automatic code modification at large scale.

ASTGrep's core is searching and rewriting code based on abstract syntax tree produced by tree-sitter. It can help you do static analysis on

Feature Highlight

  • An intuitive pattern to find and replace AST. ASTGrep's pattern looks like ordinary code you would write every day. (You can call the pattern is isomorphic to code).

  • jQuery like API for AST traversal and manipulatioin.

  • YAML configuration to write new linting rules or code modification.

  • Written in compiled language, parsing with tree-sitter and utilizing multiple cores.

  • Beautiful command line interface :)

Democratize abstract syntax tree magic and liberate one from cumbersome AST programming!

CLI Screenshot

image

Rewrite

image

Error report

image

Sponsor

If you find ASTGrep interesting and useful for your work, please buy me a coffee so I can spend more time on the project!

TODO:

Core

  • Add replace
  • Add find_all
  • Add metavar char customization
  • Add per-language customization
  • Add support for vec/sequence matcher
  • Investigate perf heuristic (e.g. match fixed-string)
  • Group matching rules based on root pattern kind id
  • View node in context
  • implement iterative DFS mode

Metavariable Matcher

  • Regex
  • Pattern
  • Kind

Rule

  • every / all
  • either / any
  • inside
  • has
  • follows
  • precedes

CLI

  • match against files in directory recursively
  • interactive mode
  • as dry run mode (listing all rewrite)
  • inplace edit mode
  • no-color mode
  • JSON output

Config

  • support YAML config rule
  • Add support for severity
  • Add support for error message
  • Add support for error labels
  • Add support for fix

Binding

  • NAPI binding
  • WASM binding
  • Python binding

Playground

  • build a playground based on WASM binding

Builtin Ruleset

  • Migrate some ESLint rule (or RSLint rule)
Languages
Rust 94.1%
TypeScript 2.3%
Python 1.9%
JavaScript 1.7%