forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis-ignored.ts
40 lines (34 loc) · 1.06 KB
/
is-ignored.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {wildcards} from './defaults.js';
import {IsIgnoredOptions} from '@commitlint/types';
import {validateIgnoreFunction} from './validate-ignore-func.js';
export default function isIgnored(
commit: string = '',
opts: IsIgnoredOptions = {}
): boolean {
const ignores = typeof opts.ignores === 'undefined' ? [] : opts.ignores;
if (!Array.isArray(ignores)) {
throw new Error(
`ignores must be of type array, received ${ignores} of type ${typeof ignores}`
);
}
// Validate ignore functions
ignores.forEach(validateIgnoreFunction);
const invalids = ignores.filter((c) => typeof c !== 'function');
if (invalids.length > 0) {
throw new Error(
`ignores must be array of type function, received items of type: ${invalids
.map((i) => typeof i)
.join(', ')}`
);
}
const base = opts.defaults === false ? [] : wildcards;
return [...base, ...ignores].some((w) => {
const result = w(commit);
if (typeof result !== 'boolean') {
throw new Error(
`Ignore function must return a boolean, received ${typeof result}`
);
}
return result;
});
}