There are many node types to detect, ie:
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.
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.
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.
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!
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With