eslint-plugin-eslint-comments
eslint-plugin-eslint-comments copied to clipboard
`no-restricted-disable`: un-disabling rules with slashes
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));
});
great thanks, this hack saves my day!
You just saved me hours of frustration, thanks!
Thanks to @kaelzhang for the original discovery!
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