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