Skip to content
Permalink
Browse files

Fix: CLIEngine#getRules() contains plugin rules (fixes #11871) (#11872)

  • Loading branch information...
mysticatea committed Jun 23, 2019
1 parent 21f4a80 commit d07f3fae19b901c30cf4998f10722cb3182bd237
@@ -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}.`);
@@ -573,7 +573,7 @@ class CLIEngine {
const linter = new Linter();

/** @type {ConfigArray[]} */
const lastConfigArrays = [];
const lastConfigArrays = [configArrayFactory.getConfigArrayForFile()];

// Store private data.
internalSlotsMap.set(this, {
@@ -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");
});
});

0 comments on commit d07f3fa

Please sign in to comment.
You can’t perform that action at this time.