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

[New] check unused rules with overrides #343

Merged
merged 1 commit into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lib/rule-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ async function _getConfigs(overrideConfigFile, files) {

async function _getConfig(configFile, files) {
return Array.from(await _getConfigs(configFile, files)).reduce((prev, item) => {
return Object.assign(prev, item, {rules: Object.assign({}, prev.rules, item.rules)});
return Object.assign(prev, item, {
rules: Object.assign({}, prev.rules, item.rules),
plugins: [...new Set([].concat(prev.plugins || [], item.plugins || []))]
});
}, {});
}

Expand Down
37 changes: 37 additions & 0 deletions test/fixtures/post-v5/eslint-with-overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"plugins": [
"plugin"
],
"rules": {
"foo-rule": [2],
"old-rule": [2],

"plugin/old-plugin-rule": [2]
},

"overrides": [
{
"files": ["**/*.json"],

"plugins": [
"@scope/scoped-plugin",
"@scope"
],
"rules": {
"@scope/scoped-plugin/foo-rule": [2],
"@scope/foo-rule": [2]
}
},
{
"files": ["**/*.txt"],

"plugins": [
"@scope-with-dash/scoped-with-dash-plugin",
"@scope-with-dash/eslint-plugin"
],
"rules": {
"@scope-with-dash/scoped-with-dash-plugin/old-plugin-rule": [2]
}
}
]
}
1 change: 1 addition & 0 deletions test/fixtures/post-v5/no-path/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some files
19 changes: 19 additions & 0 deletions test/lib/rule-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const specifiedFileAbsolute = path.join(process.cwd(), specifiedFileRelative);
const noRulesFile = path.join(process.cwd(), `./test/fixtures/${eslintVersion}/eslint-with-plugin-with-no-rules.json`);
const noDuplicateRulesFiles = `./test/fixtures/${eslintVersion}/eslint-dedupe-plugin-rules.json`;
const usingDeprecatedRulesFile = path.join(process.cwd(), `./test/fixtures/${eslintVersion}/eslint-with-deprecated-rules.json`);
const usingWithOverridesFile = path.join(process.cwd(), `./test/fixtures/${eslintVersion}/eslint-with-overrides.json`);

describe('rule-finder', function() {
// increase timeout because proxyquire adds a significant delay
Expand Down Expand Up @@ -610,4 +611,22 @@ describe('rule-finder', function() {
'plugin/old-plugin-rule'
]);
});

it('check overrides - unused rules', async () => {
const ruleFinder = await getRuleFinder(usingWithOverridesFile, {'ext': ['.txt', '.json']});
assert.deepEqual(ruleFinder.getUnusedRules(), [
"@scope-with-dash/bar-rule",
"@scope-with-dash/foo-rule",
"@scope-with-dash/scoped-with-dash-plugin/bar-rule",
"@scope-with-dash/scoped-with-dash-plugin/foo-rule",
"@scope/bar-rule",
"@scope/scoped-plugin/bar-rule",
"bar-rule",
"baz-rule",
"plugin/bar-rule",
"plugin/baz-rule",
"plugin/foo-rule",
]);
});

});