Skip to content
Permalink
Browse files

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 b5bde0669bd6a7a6b8e38cdf204d8d4b932cea63
@@ -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);
}

@@ -314,6 +314,7 @@ function defineConfigArrayFactoryWithInMemoryFileSystem({
// Override the default cwd.
return {
fs,
stubs,
RelativeModuleResolver,
ConfigArrayFactory: cwd === process.cwd
? ConfigArrayFactory
@@ -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 },
@@ -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", () => {

0 comments on commit b5bde06

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