( parsed, when = "always", value = [], )
| 22 | const negated = (when?: string) => when === "never"; |
| 23 | |
| 24 | export const subjectCase: SyncRule<TargetCaseType | TargetCaseType[]> = ( |
| 25 | parsed, |
| 26 | when = "always", |
| 27 | value = [], |
| 28 | ) => { |
| 29 | const { subject } = parsed; |
| 30 | |
| 31 | if (typeof subject !== "string" || !subject.match(startsWithLetterRegex)) { |
| 32 | return [true]; |
| 33 | } |
| 34 | |
| 35 | const checks = (Array.isArray(value) ? value : [value]).map((check) => { |
| 36 | if (typeof check === "string") { |
| 37 | return { |
| 38 | when: "always", |
| 39 | case: check, |
| 40 | }; |
| 41 | } |
| 42 | return check; |
| 43 | }); |
| 44 | |
| 45 | const result = checks.some((check) => { |
| 46 | const r = ensureCase(subject, check.case); |
| 47 | return negated(check.when) ? !r : r; |
| 48 | }); |
| 49 | |
| 50 | const list = checks.map((c) => c.case).join(", "); |
| 51 | |
| 52 | return [ |
| 53 | negated(when) ? !result : result, |
| 54 | message([`subject must`, negated(when) ? `not` : null, `be ${list}`]), |
| 55 | ]; |
| 56 | }; |
no test coverage detected
searching dependent graphs…