Skip to content

Commit ab5bf6e

Browse files
committed
feat: eslint-plugin-no-autofix support scoped plugins (fixes #77)
1 parent e875f01 commit ab5bf6e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/no-autofix/lib/rules.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,24 @@ Object.keys(builtinRules).reduce((acc, cur) => {
5151

5252

5353
// support 3rd-party plugins
54-
// TODO: find a safer way, as this is no reliable(depends on the package manager)
55-
// TODO: support scoped package. e.g. @typescript-eslint/eslint-plugin
54+
// TODO: find a safer way, as this is no reliable(depends on the package managers)
5655
// TODO: lazy loading 3rd-party plugins
5756
const root = findUp.sync("package.json", { cwd: path.join(__dirname, "../../") });
5857
const mdir = path.join(root, "../node_modules/");
59-
const plugins = fs.readdirSync(mdir).filter(it => /^eslint-plugin/u.test(it) && it !== pkg.name);
58+
const plugins = [];
59+
60+
const allModules = fs.readdirSync(mdir);
61+
const eslintPluginRegex = /^eslint-plugin/u;
62+
63+
// find eslint-plugin-xxx
64+
allModules.forEach(it => eslintPluginRegex.test(it) && it !== pkg.name && plugins.push(it));
65+
66+
// find @foo/eslint-plugin-xxx
67+
allModules.filter(it => it.startsWith("@")).forEach(it => {
68+
const pkgs = fs.readdirSync(path.join(mdir, it));
69+
70+
pkgs.forEach(_pkg => eslintPluginRegex.test(_pkg) && plugins.push(`${it}/${_pkg}`));
71+
});
6072

6173
plugins.forEach(it => {
6274
const plugin = require(it);

0 commit comments

Comments
 (0)