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.

How we can support other parsers better (babel-eslint, typescript)

See original GitHub issue

There’s a good amount of previous discussion in https://github.com/eslint/eslint/issues/4640 and part of the wish list issue, but wanted to bring up an issue for this in general.

Just wanted to brainstorm what we can do to make it easier to support experimental syntax or syntax/nodes that core rules might not know about.

  • There’s currently monkeypatching being done on VisitorKeys for estraverse to account for unknown node types as well as for escope to add variable references and visit them so not sure what we can do there except figure out how if we have add more formal hooks?
  • And there’s the issue with eslint-plugin-babel which everyone eventually stumbles upon (eslint issue -> babel-eslint -> eslint-plugin-babel). Because of the use of new syntax, users will still want to use old rules. However those rules may error out when it sees new syntax. This leads to https://github.com/babel/babel-eslint/issues/131 where either babel-eslint needs to convert the experimental syntax to something eslint rules understand (and thus the AST is different and unexpected for the rules that try to operate on the new syntax) or we copy paste a specific version of the rule and modify a line or two.

Example: I think the main difference for arrow-parens is the line https://github.com/babel/eslint-plugin-babel/blob/master/rules/arrow-parens.js#L24 to account for node.async: if (node.async) token = context.getTokenAfter(token);. However the rule can get updated upstream and will be out of sync (like in https://github.com/babel/eslint-plugin-babel/issues/63).

How can we extend built-in rules, extend on top?

  • And other parsers need to figure out a good way to run all eslint tests or eslint add integration tests (since we got https://github.com/babel/babel-eslint/issues/267 before) - there were some updates to the tester so just need to further investigate the issues there.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
not-an-aardvarkcommented, Sep 20, 2017

I just published eslint-rule-composer, which should hopefully make it easier to create variants of rules in eslint-plugin-babel without copy-pasting and changing a line.

1reaction
mysticateacommented, Jun 11, 2016

A small rough idea, it’s to add an event for parsers. My image is:

function addressARule(context) {
    var sourceCode = context.getSourceCode();
    var token = sourceCode.getFirstToken(context.reportedItem.loc);
    if (token.type === "Keyword" && token.value === "async") {
        // It can cancel this report.
        context.cancel();

        // Or it can modify this report.
        context.reportedItem.loc.column += 5;
    }
}

module.exports = {
    parse: function() {},

    // This is called in RuleContext#report(), then this modifies the report.
    onReported: function(context) {
        switch (context.ruleId) {
            case "a-rule": addressARule(context); break;
            case "another-rule": addressAnotherRule(context); break;
        }
    }
}

I think such event has smaller risk than monkey patching.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript casting with babel eslint parsing - Stack Overflow
Post this answer to provide some additional key point. @babel/eslint-parser (previously babel-eslint) can parse TS and let ESLint to work on TS.
Read more >
@babel/eslint-parser - npm
While @babel/eslint-parser can parse TypeScript, we don't currently support linting TypeScript using the rules in @babel/eslint-plugin . This is ...
Read more >
The State of babel-eslint
babel -eslint is moved to @babel/eslint-parser ! The Past. Existing as a compatibility layer between Babel and ESLint – two projects ...
Read more >
Moving from Babel, Flow, and ESLint to Typescript - Medium
I first tried to set it up for the project via typescript-eslint-parser but ran into a lot of issues with other plugins.
Read more >
Linting TypeScript | CLion Documentation - JetBrains
If you are using previous versions of ESLint, you have to install babel-eslint , typescript-eslint-parser , or eslint-plugin-typescript because ...
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