Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I view all the eslint ast node types?

There are many node types to detect, ie:

  • VariableDeclarator
  • FunctionExpression
  • MemberExpression
  • AssignmentExpression

The eslint website explains the rules but doesn't provide all of the available node type detections.

I found a tutorial example detecting IfStatement but this is not picking up my if statement, so wondering if I have a syntax error.

like image 250
Steve Tomlin Avatar asked Sep 23 '16 16:09

Steve Tomlin


People also ask

What is AST ESLint?

ESLint is a CLI tool which is wrapped around two other open source projects. One is Espree, which creates an Abstract Syntax Tree (AST) from JavaScript code. Based on this, AST ESLint uses another project called Estraverse which provides traversal functions for an AST.

What is AST node?

An AST node represents a JavaScript source code construct, such as a name, type, expression, statement, or declaration. Each AST node belongs to a unique AST instance, called the owning AST. The children of an AST node always have the same owner as their parent node.


3 Answers

Besides the ESTree documentation that you found, I would recommend: https://astexplorer.net/

It shows you the AST for the code you paste in and also highlights which part of the code each node corresponds to as you click/hover over them.

It's invaluable when writing a rule, figuring out edge cases, or in general, for understanding how the AST of a given snippet of code looks like. Give it a try!

like image 103
vitorbal Avatar answered Oct 11 '22 16:10

vitorbal


It's ok. The reason my ifstatement wasn't working was because i didn't have an if statement in the code I was testing.

Regarding the reference to all the ast node types I found that too - https://github.com/estree/estree/blob/master/es5.md

like image 29
Steve Tomlin Avatar answered Oct 11 '22 18:10

Steve Tomlin


A more up to date list (e.g., that includes ArrowFunctionExpression) is at https://github.com/benjamn/ast-types/blob/master/gen/namedTypes.ts . https://github.com/benjamn/ast-types/blob/master/gen/kinds.ts and https://github.com/benjamn/ast-types/blob/master/def/es6.ts are also interesting and may be helpful as well.

like image 40
Brett Zamir Avatar answered Oct 11 '22 17:10

Brett Zamir