Skip to content

Commit 3bf3149

Browse files
authored
feat: Check CWD before plugin directory (#20)
Fixes #17 This allows for an npm/yarn/pnpm workspace to override the eslint-local-rules of the project root. Co-authored-by: takurinton <[email protected]>
1 parent 772984f commit 3bf3149

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
var { requireUp } = require('./requireUp');
55
var { DEFAULT_EXTENSIONS } = require('./constants');
66

7-
var rules = requireUp('eslint-local-rules', DEFAULT_EXTENSIONS, __dirname);
7+
// First check for local rules in the current working directory and its ancestors (enables npm/yarn/pnpm workspaces support)
8+
var rules = requireUp('eslint-local-rules', DEFAULT_EXTENSIONS, process.cwd());
9+
10+
if (!rules) {
11+
// Then try the directory containing this plugin and its ancestors
12+
rules = requireUp('eslint-local-rules', DEFAULT_EXTENSIONS, __dirname);
13+
}
814

915
if (!rules) {
1016
throw new Error(
@@ -13,6 +19,8 @@ if (!rules) {
1319
['.js'].concat(DEFAULT_EXTENSIONS.filter(Boolean)) +
1420
'} ' +
1521
'or eslint-local-rules/index.js (checked all ancestors of "' +
22+
process.cwd() +
23+
'" and "' +
1624
__dirname +
1725
'").'
1826
);

0 commit comments

Comments
 (0)