Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jun 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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