-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathissue-match.ts
More file actions
27 lines (19 loc) · 877 Bytes
/
issue-match.ts
File metadata and controls
27 lines (19 loc) · 877 Bytes
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
27
import path from 'node: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 { createIssuePredicateFromIssueMatch };
export type { IssueMatch };