Skip to content

Commit

Permalink
Catch when no matching config found
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Jul 21, 2022
1 parent de2f8e1 commit 68d01ee
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
12 changes: 12 additions & 0 deletions lib/linter/linter.js
Expand Up @@ -1781,6 +1781,18 @@ class Linter {
internalSlotsMap.get(this).lastConfigArray = configArray;
const config = configArray.getConfig(filename);

if (!config) {
return [
{
ruleId: null,
severity: 1,
message: `No matching configuration found for ${filename}.`,
line: 0,
column: 0
}
];
}

// Verify.
if (config.processor) {
debug("Apply the processor: %o", config.processor);
Expand Down
29 changes: 23 additions & 6 deletions tests/lib/linter/linter.js
Expand Up @@ -7147,7 +7147,7 @@ var a = "test2";

it("should not modify a parser error message without a leading line: prefix", () => {
linter.defineParser("no-line-error", testParsers.noLineError);
const messages = linter.verify(";", { parser: "no-line-error" }, "filename");
const messages = linter.verify(";", { parser: "no-line-error" }, filename);
const suppressedMessages = linter.getSuppressedMessages();

assert.strictEqual(messages.length, 1);
Expand Down Expand Up @@ -7950,7 +7950,7 @@ describe("Linter with FlatConfigArray", () => {
languageOptions: {
parser: testParsers.lineError
}
}, "filename");
}, filename);
const suppressedMessages = linter.getSuppressedMessages();

assert.strictEqual(messages.length, 1);
Expand All @@ -7965,7 +7965,7 @@ describe("Linter with FlatConfigArray", () => {
languageOptions: {
parser: testParsers.noLineError
}
}, "filename");
}, filename);
const suppressedMessages = linter.getSuppressedMessages();

assert.strictEqual(messages.length, 1);
Expand Down Expand Up @@ -8278,7 +8278,7 @@ describe("Linter with FlatConfigArray", () => {

it("should report an error when JSX code is encountered and JSX is not enabled", () => {
const code = "var myDivElement = <div className=\"foo\" />;";
const messages = linter.verify(code, {}, "filename");
const messages = linter.verify(code, {}, filename);
const suppressedMessages = linter.getSuppressedMessages();

assert.strictEqual(messages.length, 1);
Expand All @@ -8299,7 +8299,7 @@ describe("Linter with FlatConfigArray", () => {
}
}
}
}, "filename");
}, filename);
const suppressedMessages = linter.getSuppressedMessages();

assert.strictEqual(messages.length, 0);
Expand All @@ -8318,7 +8318,7 @@ describe("Linter with FlatConfigArray", () => {
}
}

}, "filename");
}, "filename.js");
const suppressedMessages = linter.getSuppressedMessages();

assert.strictEqual(messages.length, 0);
Expand Down Expand Up @@ -8618,6 +8618,23 @@ describe("Linter with FlatConfigArray", () => {
assert.strictEqual(suppressedMessages.length, 0);
});

it("should report ignored file when filename isn't matched in the config array", () => {

const code = "foo()\n alert('test')";
const config = { rules: { "no-mixed-spaces-and-tabs": 1, "eol-last": 1, semi: [1, "always"] } };

const messages = linter.verify(code, config, "filename.ts");

assert.strictEqual(messages.length, 1);
assert.deepStrictEqual(messages[0], {
ruleId: null,
severity: 1,
message: "No matching configuration found for filename.ts.",
line: 0,
column: 0
});
});

describe("Plugins", () => {

it("should not load rule definition when rule isn't used", () => {
Expand Down

0 comments on commit 68d01ee

Please sign in to comment.