Repository: sarbbottam/eslint-find-rules (js)

Issue:
Support overrides
When adding TypeScript support in `eslint-config-kentcdodds` (see https://github.com/kentcdodds/eslint-config-kentcdodds/pull/54), I noticed CI isn’t failing even though I haven't added all @typescript-eslint rules (yet).

I'm happy to help out if you could point me into the right direction of adding support here. 🙂

Pull request:
[New] check unused rules with overrides
Fixes #317.

Patch:
diff --git a/src/lib/rule-finder.js b/src/lib/rule-finder.js
index ef9560d..3f8d19a 100644
--- a/src/lib/rule-finder.js
+++ b/src/lib/rule-finder.js
@@ -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 || []))]
+    });
   }, {});
 }
 


Test patch:
diff --git a/test/fixtures/post-v5/eslint-with-overrides.json b/test/fixtures/post-v5/eslint-with-overrides.json
new file mode 100644
index 0000000..553ab77
--- /dev/null
+++ b/test/fixtures/post-v5/eslint-with-overrides.json
@@ -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]
+      }
+    }
+  ]
+}
diff --git a/test/fixtures/post-v5/no-path/index.txt b/test/fixtures/post-v5/no-path/index.txt
new file mode 100644
index 0000000..7414893
--- /dev/null
+++ b/test/fixtures/post-v5/no-path/index.txt
@@ -0,0 +1,1 @@
+some files
\ No newline at end of file
diff --git a/test/lib/rule-finder.js b/test/lib/rule-finder.js
index 264ff3a..03c2ce8 100644
--- a/test/lib/rule-finder.js
+++ b/test/lib/rule-finder.js
@@ -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
@@ -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",
+    ]);
+  });
+
 });