From d07f3fae19b901c30cf4998f10722cb3182bd237 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Mon, 24 Jun 2019 03:48:55 +0900 Subject: [PATCH] Fix: CLIEngine#getRules() contains plugin rules (fixes #11871) (#11872) --- .../cascading-config-array-factory.js | 17 ++++++++++++++--- lib/cli-engine/cli-engine.js | 2 +- tests/lib/cli-engine/cli-engine.js | 7 ++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/cli-engine/cascading-config-array-factory.js b/lib/cli-engine/cascading-config-array-factory.js index 7d162e5c048..db6b4982cc7 100644 --- a/lib/cli-engine/cascading-config-array-factory.js +++ b/lib/cli-engine/cascading-config-array-factory.js @@ -27,7 +27,7 @@ const os = require("os"); const path = require("path"); const { validateConfigArray } = require("../shared/config-validator"); const { ConfigArrayFactory } = require("./config-array-factory"); -const { ConfigDependency } = require("./config-array"); +const { ConfigArray, ConfigDependency } = require("./config-array"); const loadRules = require("./load-rules"); const debug = require("debug")("eslint:cascading-config-array-factory"); @@ -225,11 +225,22 @@ class CascadingConfigArrayFactory { /** * Get the config array of a given file. - * @param {string} filePath The file path to a file. + * If `filePath` was not given, it returns the config which contains only + * `baseConfigData` and `cliConfigData`. + * @param {string} [filePath] The file path to a file. * @returns {ConfigArray} The config array of the file. */ getConfigArrayForFile(filePath) { - const { cwd } = internalSlotsMap.get(this); + const { + baseConfigArray, + cliConfigArray, + cwd + } = internalSlotsMap.get(this); + + if (!filePath) { + return new ConfigArray(...baseConfigArray, ...cliConfigArray); + } + const directoryPath = path.dirname(path.resolve(cwd, filePath)); debug(`Load config files for ${directoryPath}.`); diff --git a/lib/cli-engine/cli-engine.js b/lib/cli-engine/cli-engine.js index a2359d801e8..d298898c0d7 100644 --- a/lib/cli-engine/cli-engine.js +++ b/lib/cli-engine/cli-engine.js @@ -573,7 +573,7 @@ class CLIEngine { const linter = new Linter(); /** @type {ConfigArray[]} */ - const lastConfigArrays = []; + const lastConfigArrays = [configArrayFactory.getConfigArrayForFile()]; // Store private data. internalSlotsMap.set(this, { diff --git a/tests/lib/cli-engine/cli-engine.js b/tests/lib/cli-engine/cli-engine.js index 359970eb9f7..0e5e179b1dc 100644 --- a/tests/lib/cli-engine/cli-engine.js +++ b/tests/lib/cli-engine/cli-engine.js @@ -3796,8 +3796,13 @@ describe("CLIEngine", () => { it("should expose the list of rules", () => { const engine = new CLIEngine(); - assert.isTrue(engine.getRules().has("no-eval"), "no-eval is present"); + assert(engine.getRules().has("no-eval"), "no-eval is present"); + }); + + it("should expose the list of plugin rules", () => { + const engine = new CLIEngine({ plugins: ["node"] }); + assert(engine.getRules().has("node/no-deprecated-api"), "node/no-deprecated-api is present"); }); });