|
1 | | -import { Level, Rule } from '@commitlint/load'; |
| 1 | +import type { RuleConfigTuple } from '@commitlint/types'; |
| 2 | +import { RuleConfigSeverity } from '@commitlint/types'; |
2 | 3 |
|
3 | | -export function enumWhen(rule: Rule<string[]> | undefined) { |
4 | | - if (rule == null) { |
| 4 | +export function enumWhen(rule: RuleConfigTuple<string[]> | undefined): boolean { |
| 5 | + if (rule === undefined) { |
5 | 6 | return true; |
6 | 7 | } |
7 | 8 |
|
8 | 9 | const [level, applicable, value] = rule; |
9 | 10 |
|
10 | | - if (level == Level.Disable) { |
| 11 | + if (level === RuleConfigSeverity.Disabled) { |
11 | 12 | return true; |
12 | 13 | } |
13 | 14 |
|
14 | | - const emptyEnum = value.length == 0; |
| 15 | + const emptyEnum = value?.length === 0; |
15 | 16 |
|
16 | | - if (applicable == 'always') { |
| 17 | + if (applicable === 'always') { |
17 | 18 | return !emptyEnum; |
18 | 19 | } |
19 | 20 |
|
20 | 21 | return true; |
21 | 22 | } |
22 | 23 |
|
23 | | -export function emptyWhen(rule: Rule<undefined> | undefined) { |
24 | | - if (rule == null) { |
| 24 | +export function emptyWhen(rule: RuleConfigTuple<undefined> | undefined): boolean { |
| 25 | + if (rule === undefined) { |
25 | 26 | return true; |
26 | 27 | } |
27 | 28 |
|
28 | 29 | const [level, applicable] = rule; |
29 | 30 |
|
30 | | - if (level == Level.Disable) { |
| 31 | + if (level === RuleConfigSeverity.Disabled) { |
31 | 32 | return true; |
32 | 33 | } |
33 | 34 |
|
34 | | - return applicable == 'never'; |
| 35 | + return applicable === 'never'; |
35 | 36 | } |
36 | 37 |
|
37 | 38 | export function whenFactory( |
38 | | - enumRule: Rule<string[]> | undefined, |
39 | | - emptyRule: Rule<undefined> | undefined |
| 39 | + enumRule: RuleConfigTuple<string[]> | undefined, |
| 40 | + emptyRule: RuleConfigTuple<undefined> | undefined |
40 | 41 | ): () => boolean { |
41 | 42 | return () => { |
42 | 43 | // return false if either of the rules return false |
|
0 commit comments