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.

eslint-plugin-eslint-comments will be broken in 4.6.0

See original GitHub issue

eslint-plugin-eslint-comments is a plugin created by @mysticatea to solve the issue in https://github.com/eslint/eslint/issues/6190 of linting for unused /* eslint-disable */ comments. Since ESLint rules aren’t supposed to be aware of other rules, a plugin like this technically isn’t supposed to be possible. However it was successfully implemented by monkeypatching a private API context.eslint.report), and has been useful to a lot of people for avoiding unused disable comments.

I just realized that eslint-plugin-eslint-comments will be broken in v4.6.0 as a result of d672aef42b2950c710d598cb970d630f49b2be4b, which refactors ESLint’s internal reporting logic and removes the private API that was being monkeypatched. With the current version of ESLint on master, it is no longer possible to implement something like eslint-plugin-eslint-comments, because context objects in rules don’t have a reference to the underlying Linter instance anymore. We explicitly don’t make any guarantees about the stability of undocumented APIs, but it would still be nice to avoid breaking peoples’ linting builds if possible.

So we have a few things to consider:

  • Should we revert d672aef42b2950c710d598cb970d630f49b2be4b for now?
  • Should we reconsider adding a core feature to warn on unused disable comments? Personally, I don’t think using a plugin for this is a good solution in the long-term, because it breaks the boundaries between rules and prevents us from refactoring internal APIs.

cc @ilyavolodin @mysticatea

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
not-an-aardvarkcommented, Sep 1, 2017

I agree. For now, I think maybe it would be best to revert https://github.com/eslint/eslint/commit/d672aef42b2950c710d598cb970d630f49b2be4b until we have a better way to lint for unused directive comments.

I tried to update eslint-plugin-eslint-comments to use the public API by loading rules and running them within the plugin, but I don’t think it’s possible to make it fully work right now without accessing context.eslint/context._linter. It can check comments like // eslint-disable-line no-undef by running the no-undef rule separately, but it can’t check comments like // eslint-disable-line that apply to all rules, because it doesn’t know which rules are enabled.

In the long term, I think the best solution would be to check for unused directive comments in core, using something similar to what was discussed in https://github.com/eslint/eslint/issues/6190.

0reactions
not-an-aardvarkcommented, Sep 1, 2017

For node/this-in-event-handlers, I think it would be best to use rule composition. For example:

module.exports = {
    create(context) {
        const eslint = require("eslint");
        const linter = new eslint.Linter();

        linter.verify(context.getSourceCode(), { rules: { "no-invalid-this": "error" } })
            .filter(problem => !isInEventHandler(problem))
            .forEach(problem => {
                context.report({ message: problem.message, loc: { line: problem.line, column: problem.column - 1 });
            });
        });
    }
};

Then users could easily use node/no-invalid-this as a replacement for no-invalid-this and eslint-plugin-node wouldn’t need to copy the logic from no-invalid-this.

To avoid needing to do another traversal, maybe it would be possible to extract the listeners manually and call them as part of the node/no-invalid-this listeners, then filter out reports in the Program:exit listener.

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint-plugin-eslint-comments - npm
Start using eslint-plugin-eslint-comments in your project by running `npm i eslint-plugin-eslint-comments`. There are 1233 other projects in ...
Read more >
eslint-plugin-jsdoc/README.md - UNPKG
The CDN for eslint-plugin-jsdoc. ... how many line breaks. 222, (if any) will be checked to find a jsdoc comment block before the...
Read more >
How I solved and debugged my Webpack issue through trial ...
When webpack bundles your source code, it can become difficult to track down errors and warnings to their original location.
Read more >
eslint-plugin-eslint-comments | Yarn - Package Manager
Additional ESLint rules for ESLint directive comments (e.g. //eslint-disable-line ). Usage. Documentation. Semantic Versioning Policy.
Read more >
ESLint | WebStorm Documentation - JetBrains
WebStorm integrates with ESLint which brings a wide range of linting rules that can also be extended with plugins.
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