Skip to content

Commit d783fad

Browse files
authored
refactor: replace two filter calls with single reduce in reportFiles pattern splitting
1 parent b931e8e commit d783fad

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

src/utils.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,21 @@ export function formatErrors(
6767
);
6868
// Split positive and negative patterns to replicate micromatch semantics:
6969
// a file must match a positive pattern AND not match any negative pattern.
70-
const positivePatterns = loaderOptions.reportFiles.filter(
71-
p => !p.startsWith('!')
72-
);
73-
const negativePatterns = loaderOptions.reportFiles
74-
.filter(p => p.startsWith('!'))
75-
.map(p => p.slice(1));
70+
const { positivePatterns, negativePatterns } =
71+
loaderOptions.reportFiles.reduce<{
72+
positivePatterns: string[];
73+
negativePatterns: string[];
74+
}>(
75+
(acc, p) => {
76+
if (p.startsWith('!')) {
77+
acc.negativePatterns.push(p.slice(1));
78+
} else {
79+
acc.positivePatterns.push(p);
80+
}
81+
return acc;
82+
},
83+
{ positivePatterns: [], negativePatterns: [] }
84+
);
7685
const matchPos = picomatch(
7786
positivePatterns.length > 0 ? positivePatterns : ['**']
7887
);

0 commit comments

Comments
 (0)