Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 1.19 KB

File metadata and controls

36 lines (29 loc) · 1.19 KB

Abstract Syntax Trees

  • AST is a concept to transform source code into data structures that are easy to work with for various static analysis tools, e.g. ESLint's espree

  • AST visualizer

  • AST Explorer

  • Esprima

  • Parsers transform code into Syntax Trees, they might diffefrom one another due to different implementation goals

  • Visitor pattern allows you to traverse the tree and perform some action on each node, e.g.

    // ESLint example
    function create(context) {
      return {
        // This executes for every node with if statement
        IfStatement(node) {
          if (node.consequent.type !== "BlockStatement") {
            context.report({
              node,
              message: "Use blocks with if statements",
            });
          }
        },
      };
    }
  • Creating custom ESLint rules

ESLint plugins

Babel plugins

Codemods