From b5bde0669bd6a7a6b8e38cdf204d8d4b932cea63 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Tue, 25 Jun 2019 10:03:39 +0900 Subject: [PATCH] Fix: --rulesdir option didn't work (fixes #11888) (#11890) --- .../cascading-config-array-factory.js | 1 + tests/lib/cli-engine/_utils.js | 5 +-- tests/lib/cli-engine/cli-engine.js | 32 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/cli-engine/cascading-config-array-factory.js b/lib/cli-engine/cascading-config-array-factory.js index db6b4982cc7..13b240f12b3 100644 --- a/lib/cli-engine/cascading-config-array-factory.js +++ b/lib/cli-engine/cascading-config-array-factory.js @@ -313,6 +313,7 @@ class CascadingConfigArrayFactory { if (configArray.length > 0 && configArray.isRoot()) { debug("Stop traversing because of 'root:true'."); + configArray.unshift(...baseConfigArray); return this._cacheConfig(directoryPath, configArray); } diff --git a/tests/lib/cli-engine/_utils.js b/tests/lib/cli-engine/_utils.js index 54a49b595b4..a3c56484c64 100644 --- a/tests/lib/cli-engine/_utils.js +++ b/tests/lib/cli-engine/_utils.js @@ -314,6 +314,7 @@ function defineConfigArrayFactoryWithInMemoryFileSystem({ // Override the default cwd. return { fs, + stubs, RelativeModuleResolver, ConfigArrayFactory: cwd === process.cwd ? ConfigArrayFactory @@ -336,9 +337,9 @@ function defineCascadingConfigArrayFactoryWithInMemoryFileSystem({ cwd = process.cwd, files = {} } = {}) { - const { fs, RelativeModuleResolver, ConfigArrayFactory } = + const { fs, stubs, RelativeModuleResolver, ConfigArrayFactory } = defineConfigArrayFactoryWithInMemoryFileSystem({ cwd, files }); - const loadRules = proxyquire(LoadRulesPath, { fs }); + const loadRules = proxyquire(LoadRulesPath, stubs); const { CascadingConfigArrayFactory } = proxyquire(CascadingConfigArrayFactoryPath, { "./config-array-factory": { ConfigArrayFactory }, diff --git a/tests/lib/cli-engine/cli-engine.js b/tests/lib/cli-engine/cli-engine.js index 9e54fc7c227..de152f3bae8 100644 --- a/tests/lib/cli-engine/cli-engine.js +++ b/tests/lib/cli-engine/cli-engine.js @@ -3422,6 +3422,38 @@ describe("CLIEngine", () => { assert.fail("Expected to throw an error"); }); }); + + describe("with '--rulesdir' option", () => { + it("should use the configured rules which are defined by '--rulesdir' option.", () => { + const rootPath = getFixturePath("cli-engine/with-rulesdir"); + const StubbedCLIEngine = defineCLIEngineWithInMemoryFileSystem({ + cwd: () => rootPath, + files: { + "internal-rules/test.js": ` + module.exports = context => ({ + ExpressionStatement(node) { + context.report({ node, message: "ok" }) + } + }) + `, + ".eslintrc.json": JSON.stringify({ + root: true, + rules: { test: "error" } + }), + "test.js": "console.log('hello')" + } + }).CLIEngine; + + engine = new StubbedCLIEngine({ + rulePaths: ["internal-rules"] + }); + const report = engine.executeOnFiles(["test.js"]); + + assert.strictEqual(report.results.length, 1); + assert.strictEqual(report.results[0].messages.length, 1); + assert.strictEqual(report.results[0].messages[0].message, "ok"); + }); + }); }); describe("getConfigForFile", () => {