From 8a52d69beb25eccb8779dd68928a2cb0cc0829cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20Marohni=C4=87?= Date: Thu, 23 Jan 2020 14:34:30 +0100 Subject: [PATCH] Fix loading rules when using Jest 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. --- index.js | 9 +++++++-- package.json | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 840392a..84bf13b 100644 --- a/index.js +++ b/index.js @@ -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' diff --git a/package.json b/package.json index 6d97a56..7464862 100644 --- a/package.json +++ b/package.json @@ -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",