Skip to content

Commit

Permalink
Fix loading rules when using Jest
Browse files Browse the repository at this point in the history
req-all relies on `require.extensions` under the hood, which gets
modified by Jest, so loading rules in Jest (e.g. via ESLint Node.js API)
doesn't work, it just results in an empty object.

Since we're loading our own files, we don't need some complicated logic
to do this, we can roll our own.
  • Loading branch information
silvenon committed Jan 23, 2020
1 parent 205861e commit 8a52d69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use strict';

const reqAll = require('req-all');
const fs = require('fs');
const path = require('path');
const createIndex = require('create-eslint-index');

const rules = reqAll('rules', {camelize: false});
const rules = {};
for (const file of fs.readdirSync(`${__dirname}/rules`)) {
const ruleName = path.basename(file, path.extname(file));
rules[ruleName] = require(`./rules/${ruleName}`);
}

const externalRecommendedRules = {
'no-var': 'error'
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
"dependencies": {
"create-eslint-index": "^1.0.0",
"eslint-ast-utils": "^1.0.0",
"lodash": "^4.13.1",
"req-all": "^0.1.0"
"lodash": "^4.13.1"
},
"devDependencies": {
"ava": "^0.17.0",
Expand Down

0 comments on commit 8a52d69

Please sign in to comment.