Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nemoDreamer opened this issue May 13, 2020 · 4 comments
Open

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

nemoDreamer opened this issue May 13, 2020 · 4 comments

Comments

@nemoDreamer
Copy link

nemoDreamer commented May 13, 2020

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
Copy link

yfhui commented Jan 10, 2023

great thanks, this hack saves my day!

@richyk1
Copy link

richyk1 commented Sep 14, 2023

You just saved me hours of frustration, thanks!

@nemoDreamer
Copy link
Author

Thanks to @kaelzhang for the original discovery!

@MichaelDeBoey
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants