Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: --rulesdir option didn't work (fixes #11888) (#11890)
  • Loading branch information
mysticatea authored and not-an-aardvark committed Jun 25, 2019
1 parent 13f0418 commit b5bde06
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/cli-engine/cascading-config-array-factory.js
Expand Up @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions tests/lib/cli-engine/_utils.js
Expand Up @@ -314,6 +314,7 @@ function defineConfigArrayFactoryWithInMemoryFileSystem({
// Override the default cwd.
return {
fs,
stubs,
RelativeModuleResolver,
ConfigArrayFactory: cwd === process.cwd
? ConfigArrayFactory
Expand All @@ -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 },
Expand Down
32 changes: 32 additions & 0 deletions tests/lib/cli-engine/cli-engine.js
Expand Up @@ -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", () => {
Expand Down

0 comments on commit b5bde06

Please sign in to comment.