Skip to content

Commit ba44647

Browse files
dtinthcletusw
authored andcommitted
Fix VS Code integration when ESLint project outside VS Code project
When an ESLint project is not in the root directory, e.g. + our-project |--+ client | |--- src/ | |--- package.json | |--- eslint-local-rules.js |--+ server | |--- stuff Some editor plugins does not `cd` into `client` directory when invoking ESLint. Therefore `process.cwd()` is "our-project", which means `requireUp` will not find our "eslint-local-rules.js". This problem is fixed by making this plugin require from `__dirname` instead of `process.cwd()`. Intuitively, the behavior of the plugin should not depend on where it is run. This commit also makes `eslint-plugin-local-rules` fail loudly if the rules file is not found.
1 parent fc46d2e commit ba44647

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33

44
var path = require('path');
55

6-
var rules = requireUp('eslint-local-rules.js');
6+
var rules = requireUp('eslint-local-rules.js', __dirname);
7+
8+
if (!rules) {
9+
throw new Error(
10+
'eslint-plugin-local-rules: ' +
11+
'Cannot find "eslint-local-rules.js" ' +
12+
'(looking up from "' + __dirname + '").'
13+
);
14+
}
715

816
module.exports = {
917
rules: rules,
@@ -13,7 +21,6 @@ module.exports = {
1321
// Similar to native `require` behavior, but doesn't check in `node_modules` folders
1422
// Based on https://github.com/js-cli/node-findup-sync
1523
function requireUp(filename, cwd) {
16-
cwd = cwd || process.cwd();
1724
var filepath = path.resolve(cwd, filename);
1825

1926
try {

0 commit comments

Comments
 (0)