Skip to content

Commit

Permalink
Fix: CLIEngine#getRules() contains plugin rules (fixes #11871) (#11872)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jun 23, 2019
1 parent 21f4a80 commit d07f3fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
17 changes: 14 additions & 3 deletions lib/cli-engine/cascading-config-array-factory.js
Expand Up @@ -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");

Expand Down Expand Up @@ -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}.`);
Expand Down
2 changes: 1 addition & 1 deletion lib/cli-engine/cli-engine.js
Expand Up @@ -573,7 +573,7 @@ class CLIEngine {
const linter = new Linter();

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

// Store private data.
internalSlotsMap.set(this, {
Expand Down
7 changes: 6 additions & 1 deletion tests/lib/cli-engine/cli-engine.js
Expand Up @@ -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");
});
});

Expand Down

0 comments on commit d07f3fa

Please sign in to comment.