mysticatea / eslint-plugin-eslint-comments

Additional ESLint rules for directive comments of ESLint.
https://mysticatea.github.io/eslint-plugin-eslint-comments/
MIT License
361 stars 46 forks source link

`no-restricted-disable`: un-disabling rules with slashes #46

Open nemoDreamer opened 4 years ago

nemoDreamer commented 4 years ago

Hi, I was following the examples for https://mysticatea.github.io/eslint-plugin-eslint-comments/rules/no-restricted-disable.html and noticed that the underlying ignore package handles un-ignores after '*' strangely.

When you lock down disabling of all rules with '*', you can't allow scope/rule-type rules later, unless you explicitly allow '*/'.

I finally found my answer in the fixtures of https://github.com/kaelzhang/node-ignore 😆

Here's a snippet to recreate:

#!/usr/bin/env node

const ignore = require('ignore');

const rules = ignore();

// set up
rules.add([
    // ignore all:
    '*',
    '!*/', // (undocumented hack found in https://github.com/kaelzhang/node-ignore/blob/master/test/fixtures/cases.js#L276)
    // un-ignore these:
    '!no-console',
    '!react/boolean-prop-naming',
]);

// test
[
    'no-console', // false ✅
    'react/boolean-prop-naming', // false ✅
    'boolean-prop-naming', // true ✅
    'something-else', // true ✅
    'something/else', // true ✅
    'another/thing-with-hyphens', // true ✅
].forEach(rule => {
    // eslint-disable-next-line no-console
    console.log(rule, rules.ignores(rule));
});
yfhui commented 1 year ago

great thanks, this hack saves my day!

richyk1 commented 1 year ago

You just saved me hours of frustration, thanks!

nemoDreamer commented 1 year ago

Thanks to @kaelzhang for the original discovery!

MichaelDeBoey commented 1 year ago

Hi @nemoDreamer!

Since this repo is unmaintained, you might want to re-open this issue in the @eslint-community fork https://github.com/eslint-community/eslint-plugin-eslint-comments

For more info about why we created this organization, you can read https://eslint.org/blog/2023/03/announcing-eslint-community-org