question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow valid/invalid cases in RuleTester to contain a syntax tree instead of example code

See original GitHub issue

The 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:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Jul 8, 2021

Glad it helped!

I’m using the parser directly, e.g.:

const ts = require("@typescript-eslint/parser");

const code = "foo";
const ast = ts.parse(code, {
    tokens: true,
    comment: true,
    range: true,
    loc: true
});

// then stringify, save to file, etc.

astexplorer.net should do the same, but you’ll need to enable the options that are not set by default (loc, comment, and tokens):

image

image

0reactions
nzakascommented, Aug 21, 2021

I don’t think we are going to move forward with a change here, as there are better options available.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no support for logical nullish assignment operator · Issue #147
Please report a minimal code snippet to the developers at (github url) ... Allow valid/invalid cases in RuleTester to contain a syntax tree...
Read more >
Node.js API - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
How I built my first custom ESLint rule - Maxime Heckel's Blog
This is what this article is about: how I built this specific rule and how I learned about "Abstract Syntax Tree". Let's dive...
Read more >
ast — Abstract Syntax Trees — Python 3.11.1 documentation
AST . An abstract syntax tree can be compiled into a Python code object using the built-in compile() function.
Read more >
Enforcing good practices in the front-end - Medium
In the example, the provided message contains 2 placeholders: ... The linter parses our code to build an Abstract Syntax Tree out of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found