forked from TypeStrong/fork-ts-checker-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue-match.ts
26 lines (18 loc) · 852 Bytes
/
issue-match.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import path from 'path';
import minimatch from 'minimatch';
import { forwardSlash } from '../utils/path/forward-slash';
import type { IssuePredicate } from './issue-predicate';
import type { Issue } from './index';
type IssueMatch = Partial<Pick<Issue, 'severity' | 'code' | 'file'>>;
function createIssuePredicateFromIssueMatch(context: string, match: IssueMatch): IssuePredicate {
return (issue) => {
const matchesSeverity = !match.severity || match.severity === issue.severity;
const matchesCode = !match.code || match.code === issue.code;
const matchesFile =
!issue.file ||
(!!issue.file &&
(!match.file || minimatch(forwardSlash(path.relative(context, issue.file)), match.file)));
return matchesSeverity && matchesCode && matchesFile;
};
}
export { IssueMatch, createIssuePredicateFromIssueMatch };