Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit04c7188

Browse files
authored
fix: Don't lint same file multiple times (#18899)
1 parent87ec3c4 commit04c7188

File tree

3 files changed

+62
-25
lines changed

3 files changed

+62
-25
lines changed

‎lib/eslint/eslint-helpers.js‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ async function globMultiSearch({ searches, configs, errorOnUnmatchedPattern }) {
484484

485485
}
486486

487-
return[...newSet(filePaths)];
487+
returnfilePaths;
488488

489489
}
490490

@@ -533,10 +533,7 @@ async function findFiles({
533533

534534
// files are added directly to the list
535535
if(stat.isFile()){
536-
results.push({
537-
filePath,
538-
ignored:configs.isFileIgnored(filePath)
539-
});
536+
results.push(filePath);
540537
}
541538

542539
// directories need extensions attached
@@ -594,11 +591,10 @@ async function findFiles({
594591
});
595592

596593
return[
597-
...results,
598-
...globbyResults.map(filePath=>({
599-
filePath:path.resolve(filePath),
600-
ignored:false
601-
}))
594+
...newSet([
595+
...results,
596+
...globbyResults.map(filePath=>path.resolve(filePath))
597+
])
602598
];
603599
}
604600

‎lib/eslint/flat-eslint.js‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -790,31 +790,22 @@ class FlatESLint {
790790
*/
791791
constresults=awaitPromise.all(
792792

793-
filePaths.map(({ filePath, ignored})=>{
793+
filePaths.map(filePath=>{
794+
795+
constconfig=configs.getConfig(filePath);
794796

795797
/*
796-
* If a filename was entered thatmatches an ignore
797-
*pattern, then notify the user.
798+
* If a filename was entered thatcannot be matched
799+
*to a config, then notify the user.
798800
*/
799-
if(ignored){
801+
if(!config){
800802
if(warnIgnored){
801803
returncreateIgnoreResult(filePath,cwd);
802804
}
803805

804806
returnvoid0;
805807
}
806808

807-
constconfig=configs.getConfig(filePath);
808-
809-
/*
810-
* Sometimes a file found through a glob pattern will
811-
* be ignored. In this case, `config` will be undefined
812-
* and we just silently ignore the file.
813-
*/
814-
if(!config){
815-
returnvoid0;
816-
}
817-
818809
// Skip if there is cached result.
819810
if(lintResultCache){
820811
constcachedResult=

‎tests/lib/eslint/flat-eslint.js‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,56 @@ describe("FlatESLint", () => {
10371037
awaitassert.rejects(async()=>awaiteslint.lintFiles(["lib/cli.js"]),/Expectedobjectwithparse\(\)orparseForESLint\(\)method/u);
10381038
});
10391039

1040+
describe("Overlapping searches",()=>{
1041+
it("should not lint the same file multiple times when the file path was passed multiple times",async()=>{
1042+
constcwd=getFixturePath();
1043+
1044+
eslint=newFlatESLint({
1045+
cwd,
1046+
overrideConfigFile:true
1047+
});
1048+
1049+
constresults=awaiteslint.lintFiles(["files/foo.js","files/../files/foo.js","files/foo.js"]);
1050+
1051+
assert.strictEqual(results.length,1);
1052+
assert.strictEqual(results[0].filePath,path.resolve(cwd,"files/foo.js"));
1053+
assert.strictEqual(results[0].messages.length,0);
1054+
assert.strictEqual(results[0].suppressedMessages.length,0);
1055+
});
1056+
1057+
it("should not lint the same file multiple times when the file path and a pattern that matches the file were passed",async()=>{
1058+
constcwd=getFixturePath();
1059+
1060+
eslint=newFlatESLint({
1061+
cwd,
1062+
overrideConfigFile:true
1063+
});
1064+
1065+
constresults=awaiteslint.lintFiles(["files/foo.js","files/foo*"]);
1066+
1067+
assert.strictEqual(results.length,1);
1068+
assert.strictEqual(results[0].filePath,path.resolve(cwd,"files/foo.js"));
1069+
assert.strictEqual(results[0].messages.length,0);
1070+
assert.strictEqual(results[0].suppressedMessages.length,0);
1071+
});
1072+
1073+
it("should not lint the same file multiple times when multiple patterns that match the file were passed",async()=>{
1074+
constcwd=getFixturePath();
1075+
1076+
eslint=newFlatESLint({
1077+
cwd,
1078+
overrideConfigFile:true
1079+
});
1080+
1081+
constresults=awaiteslint.lintFiles(["files/f*.js","files/foo*"]);
1082+
1083+
assert.strictEqual(results.length,1);
1084+
assert.strictEqual(results[0].filePath,path.resolve(cwd,"files/foo.js"));
1085+
assert.strictEqual(results[0].messages.length,0);
1086+
assert.strictEqual(results[0].suppressedMessages.length,0);
1087+
});
1088+
});
1089+
10401090
it("should report zero messages when given a directory with a .js2 file",async()=>{
10411091
eslint=newFlatESLint({
10421092
cwd:path.join(fixtureDir,".."),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp