Skip to content

Commit 2d8834e

Browse files
allow importing eslint-local-rules directories (#6)
This slightly changes the "resolveUp" logic to consider the module path without extension, to let Node.js resolve it with its own logic[1]. Because Node.js will test for .js extension, we don't need to include it in `exts`. This way, using a eslint-local-rules folder containing a index.js file can be used to expose local rules. It is useful when the eslint-local-rules.js file gets a bit big and we need to split it to separate each rule in its own file. [1]: https://nodejs.org/api/modules.html#modules_all_together
1 parent 46676f9 commit 2d8834e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

index.js

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

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

6-
var exts = ['js', 'cjs'];
6+
// Empty extension takes advantage of Node's default require behavior to check for
7+
// eslint-local-rules.js as well as an eslint-local-rules folder with an index.js
8+
var exts = ['', '.cjs'];
79
var rules = requireUp('eslint-local-rules', __dirname);
810

911
if (!rules) {
@@ -26,7 +28,7 @@ function requireUp(filename, cwd) {
2628

2729
for (var i = 0; i < exts.length; i++) {
2830
try {
29-
return require(filepath + '.' + exts[i]);
31+
return require(filepath + exts[i]);
3032
} catch(error) {
3133
// Ignore OS errors (will recurse to parent directory)
3234
if (error.code !== 'MODULE_NOT_FOUND') {

0 commit comments

Comments
 (0)