Skip to content

Commit 640e16f

Browse files
conartist6cletusw
authored andcommitted
Support cjs
1 parent 6d0b4a2 commit 640e16f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33

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

6-
var rules = requireUp('eslint-local-rules.js', __dirname);
6+
var exts = ['js', 'cjs'];
7+
var rules = requireUp('eslint-local-rules', __dirname);
78

89
if (!rules) {
910
throw new Error(
1011
'eslint-plugin-local-rules: ' +
11-
'Cannot find "eslint-local-rules.js" ' +
12+
'Cannot find "eslint-local-rules.{' + exts.join(',') + "}" +
1213
'(looking up from "' + __dirname + '").'
1314
);
1415
}
@@ -23,12 +24,14 @@ module.exports = {
2324
function requireUp(filename, cwd) {
2425
var filepath = path.resolve(cwd, filename);
2526

26-
try {
27-
return require(filepath);
28-
} catch(error) {
29-
// Ignore OS errors (will recurse to parent directory)
30-
if (error.code !== 'MODULE_NOT_FOUND') {
31-
throw error;
27+
for (var i = 0; i < exts.length; i++) {
28+
try {
29+
return require(filepath + '.' + exts[i]);
30+
} catch(error) {
31+
// Ignore OS errors (will recurse to parent directory)
32+
if (error.code !== 'MODULE_NOT_FOUND') {
33+
throw error;
34+
}
3235
}
3336
}
3437

0 commit comments

Comments
 (0)