|
| 1 | +// Regression tests for "as const" compatibility. |
| 2 | +// See: https://github.com/conventional-changelog/commitlint/pull/4633 |
| 3 | +// |
| 4 | +// These are compile-time type checks (no runtime behaviour). |
| 5 | +// If a line fails to compile, the associated type definition needs to be fixed. |
| 6 | + |
| 7 | +import { RuleConfigSeverity, type RulesConfig } from "./index.js"; |
| 8 | + |
| 9 | +const ERROR = RuleConfigSeverity.Error; |
| 10 | + |
| 11 | +// ── scope-enum ──────────────────────────────────────────────────────────────── |
| 12 | + |
| 13 | +// Object form: fixed in commit 26179a4 |
| 14 | +const _scopeEnumObject = [ |
| 15 | + ERROR, |
| 16 | + "always", |
| 17 | + { scopes: ["foo", "bar"] as const }, |
| 18 | +] as const; |
| 19 | +const _scopeEnumObjectCheck: Partial<RulesConfig> = { |
| 20 | + "scope-enum": _scopeEnumObject, |
| 21 | +}; |
| 22 | +void _scopeEnumObjectCheck; |
| 23 | + |
| 24 | +// Simple array form: the primary use case from the PR. |
| 25 | +// This fails until EnumRuleConfig is changed from string[] to readonly string[]. |
| 26 | +const _scopeEnumSimple = [ERROR, "always", ["foo", "baz", "baz"]] as const; |
| 27 | +const _scopeEnumSimpleCheck: Partial<RulesConfig> = { |
| 28 | + "scope-enum": _scopeEnumSimple, |
| 29 | +}; |
| 30 | +void _scopeEnumSimpleCheck; |
| 31 | + |
| 32 | +// ── scope-case ──────────────────────────────────────────────────────────────── |
| 33 | + |
| 34 | +// Object form: fixed in commit 26179a4 |
| 35 | +const _scopeCaseObject = [ |
| 36 | + ERROR, |
| 37 | + "always", |
| 38 | + { cases: ["camel-case"] as const, delimiters: ["-"] as const }, |
| 39 | +] as const; |
| 40 | +const _scopeCaseObjectCheck: Partial<RulesConfig> = { |
| 41 | + "scope-case": _scopeCaseObject, |
| 42 | +}; |
| 43 | +void _scopeCaseObjectCheck; |
0 commit comments