eslint-plugin-eslint-comments icon indicating copy to clipboard operation
eslint-plugin-eslint-comments copied to clipboard

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

Open nemoDreamer opened this issue 5 years ago • 4 comments

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));
});

nemoDreamer avatar May 13 '20 15:05 nemoDreamer

great thanks, this hack saves my day!

yfhui avatar Jan 10 '23 08:01 yfhui

You just saved me hours of frustration, thanks!

richyk1 avatar Sep 14 '23 10:09 richyk1

Thanks to @kaelzhang for the original discovery!

nemoDreamer avatar Oct 02 '23 14:10 nemoDreamer

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

MichaelDeBoey avatar Oct 14 '23 15:10 MichaelDeBoey