Allow valid/invalid cases in RuleTester to contain a syntax tree instead of example code
See original GitHub issueThe version of ESLint you are using. v7.30.0
The problem you want to solve. Background: I am maintaining an eslint plugin that tries to detect DOM-based XSS. This plugin is very specific to Mozilla and uses our own set of trades-off in terms of false positives and false negatives. We don’t claim perfect detection and there are some obvious gaps that one has to accept when dealing with a dynamically typed, multi-paradigm language. However, this plugin has gained adoption outside of Mozilla and other projects are using it as well (Microsoft Edge, Wire IM, Kibana, …)
Precise use-case: We have some logic that tries to be exhaustive in terms of Expressions we can analyze. In particular, it is complaining for expressions that are not within a list of allowed expressions. This helps maintain the security guarantees we provide in our plugin and acts as a forcing function to adopt new JavaScript Syntax in lock-step with the tooling that is used to check it (here’s an example for the nullish assignment operator).
Currently, we can not write a test for this scenario, becaus we cannot write code containing a “FantasyExpression”.
It would be really nice to test this behavior using the RuleTester
by providing an ast
instead of a code
attribute.
Your take on the correct solution to problem.
Instead of requiring a code
sample in RuleTester only require it optionally and allow ast
instead.
Are you willing to submit a pull request to implement this change? Yes
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Glad it helped!
I’m using the parser directly, e.g.:
astexplorer.net should do the same, but you’ll need to enable the options that are not set by default (loc, comment, and tokens):
I don’t think we are going to move forward with a change here, as there are better options available.