Skip to content

Commit ce22011

Browse files
committed
chore: add tests
1 parent 26179a4 commit ce22011

5 files changed

Lines changed: 52 additions & 5 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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;

@commitlint/types/src/rules.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ export type RuleConfig<
7878

7979
export type CaseRuleConfig<V = RuleConfigQuality.User> = RuleConfig<
8080
V,
81-
TargetCaseType | TargetCaseType[]
81+
TargetCaseType | readonly TargetCaseType[]
8282
>;
8383
export type LengthRuleConfig<V = RuleConfigQuality.User> = RuleConfig<
8484
V,
8585
number
8686
>;
8787
export type EnumRuleConfig<V = RuleConfigQuality.User> = RuleConfig<
8888
V,
89-
string[]
89+
readonly string[]
9090
>;
9191
export type ObjectRuleConfig<
9292
V = RuleConfigQuality.User,

@commitlint/types/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"outDir": "./lib"
77
},
88
"include": ["./src"],
9-
"exclude": ["./lib/**/*"]
9+
"exclude": ["./src/**/*.test-d.ts", "./lib/**/*"]
1010
}

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "./tsconfig.shared.json",
33
"files": [],
4-
"include": ["./**/*.test.ts", "./**/*-test.ts"],
4+
"include": ["./**/*.test.ts", "./**/*-test.ts", "./**/*.test-d.ts"],
55
"exclude": ["./**/lib/*.ts"],
66
"compilerOptions": {
77
"noEmit": true
@@ -29,6 +29,7 @@
2929
{ "path": "@commitlint/prompt" },
3030
{ "path": "@commitlint/cz-commitlint" },
3131
{ "path": "@commitlint/config-conventional" },
32-
{ "path": "@commitlint/config-pnpm-scopes" }
32+
{ "path": "@commitlint/config-pnpm-scopes" },
33+
{ "path": "@commitlint/types" }
3334
]
3435
}

vitest.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { defineConfig } from "vitest/config";
22

33
export default defineConfig({
44
test: {
5+
typecheck: {
6+
enabled: true,
7+
},
58
exclude: ["**/node_modules/**", "**/lib/*.test.js"],
69
environment: "commitlint",
710
coverage: {

0 commit comments

Comments
 (0)