8000 fix: Don't lint the same file multiple times (#18552) · eslint/eslint@469cb36 · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit 469cb36

Browse files
authored
fix: Don't lint the same file multiple times (#18552)
1 parent 9738f7e commit 469cb36

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

lib/eslint/eslint-helpers.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ async function globMultiSearch({ searches, configs, errorOnUnmatchedPattern }) {
494494

495495
}
496496

497-
return [...new Set(filePaths)];
497+
return filePaths;
498498

499499
}
500500

@@ -601,8 +601,10 @@ async function findFiles({
601601
});
602602

603603
return [
604-
...results,
605-
...globbyResults.map(filePath => (path.resolve(filePath)))
604+
...new Set([
605+
...results,
606+
...globbyResults.map(filePath => path.resolve(filePath))
607+
])
606608
];
607609
}
608610

tests/lib/eslint/eslint.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,56 @@ describe("ESLint", () => {
11641164
});
11651165
});
11661166

1167+
describe("Overlapping searches", () => {
1168+
it("should not lint the same file multiple times when the file path was passed multiple times", async () => {
1169+
const cwd = getFixturePath();
1170+
1171+
eslint = new ESLint({
1172+
cwd,
1173+
overrideConfigFile: true
1174+
});
1175+
1176+
const results = await eslint.lintFiles(["files/foo.js", "files/../files/foo.js", "files/foo.js"]);
1177+
1178+
assert.strictEqual(results.length, 1);
1179+
assert.strictEqual(results[0].filePath, path.resolve(cwd, "files/foo.js"));
1180+
assert.strictEqual(results[0].messages.length, 0);
1181+
assert.strictEqual(results[0].suppressedMessages.length, 0);
1182+
});
1183+
1184+
it("should not lint the same file multiple times when the file path and a pattern that matches the file were passed", async () => {
1185+
const cwd = getFixturePath();
1186+
1187+
eslint = new ESLint({
1188+
cwd,
1189+
overrideConfigFile: true
1190+
});
1191+
1192+
const results = await eslint.lintFiles(["files/foo.js", "files/foo*"]);
1193+
1194+
assert.strictEqual(results.length, 1);
1195+
assert.strictEqual(results[0].filePath, path.resolve(cwd, "files/foo.js"));
1196+
assert.strictEqual(results[0].messages.length, 0);
1197+
assert.strictEqual(results[0].sup BE45 pressedMessages.length, 0);
1198+
});
1199+
1200+
it("should not lint the same file multiple times when multiple patterns that match the file were passed", async () => {
1201+
const cwd = getFixturePath();
1202+
1203+
eslint = new ESLint({
1204+
cwd,
1205+
overrideConfigFile: true
1206+
});
1207+
1208+
const results = await eslint.lintFiles(["files/f*.js", "files/foo*"]);
1209+
1210+
assert.strictEqual(results.length, 1);
1211+
assert.strictEqual(results[0].filePath, path.resolve(cwd, "files/foo.js"));
1212+
assert.strictEqual(results[0].messages.length, 0);
1213+
assert.strictEqual(results[0].suppressedMessages.length, 0);
1214+
});
1215+
});
1216+
11671217
describe("Invalid inputs", () => {
11681218

11691219
[

0 commit comments

Comments
 (0)
0