Skip to content

Commit dcda920

Browse files
z825316969youncccat
authored andcommitted
[Add::rules] add breakChangeSymbol rules
1 parent 066cc44 commit dcda920

File tree

6 files changed

+132
-60
lines changed

6 files changed

+132
-60
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { RuleResolver } from "./typings";
2+
import { breakChangeSymbol } from "./constants";
3+
4+
const breakChangeSymbolRuleResolver: RuleResolver = (
5+
parsed,
6+
_when,
7+
value = breakChangeSymbol
8+
) => {
9+
const rawCommitMessage = parsed.raw;
10+
if (!rawCommitMessage) return [false, "Commit message should not be empty"];
11+
12+
let isRuleValid = false;
13+
14+
const findedBreakChangeSymbol: string = rawCommitMessage.split("[")[0];
15+
16+
// 查找[ 前一项
17+
if (!findedBreakChangeSymbol || findedBreakChangeSymbol === value)
18+
isRuleValid = true;
19+
20+
return [
21+
isRuleValid,
22+
`break change must be symbol with "${value}" e.g: ${value}[Type::scope] subject`,
23+
];
24+
};
25+
export default breakChangeSymbolRuleResolver;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const breakChangeSymbol: string = "!";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import breakChangeSymbolRuleResolver from "../break-change-symbol-rule-resolver";
2+
3+
describe("breakChangeSymbolRuleResolver", () => {
4+
it("should return a error response if breakChangeSymbol is not !", () => {
5+
const parsed = {
6+
raw: "$[Type::scope] subject",
7+
};
8+
expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(false);
9+
});
10+
it("should return a success response if no breakChangeSymbol", () => {
11+
const parsed = {
12+
raw: "[Type::scope] subject",
13+
};
14+
expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(true);
15+
});
16+
it("should return a success response if breakChangeSymbol is !", () => {
17+
const parsed = {
18+
raw: "![Type::scope] subject",
19+
};
20+
expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(true);
21+
});
22+
});

packages/commitlint-plugin-wizardoc-rules/src/tests/foo.test.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export type RuleResolver = (
2+
parsed: Partial<{
3+
type: string;
4+
scope: string;
5+
subject: string;
6+
merge: string;
7+
header: string;
8+
body: string;
9+
footer: string;
10+
notes: string[];
11+
references: string[];
12+
mentions: string[];
13+
revert: string;
14+
raw: string;
15+
}>,
16+
when?: string,
17+
value?: string | number | boolean | (string | number)[]
18+
) => (string | boolean)[];
19+
20+
export interface CommitlintPlugin {
21+
rules: {
22+
[key: string]: RuleResolver;
23+
};
24+
}
25+
declare const commitlintPlugin: CommitlintPlugin;
26+
27+
export default commitlintPlugin;

packages/commitlint-wizardoc-e2e-tests/yarn.lock

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,78 @@
33

44

55
"@types/node@^15.3":
6-
version "15.6.1"
7-
resolved "https://registry.npmjs.org/@types/node/-/node-15.6.1.tgz#32d43390d5c62c5b6ec486a9bc9c59544de39a08"
8-
integrity sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA==
6+
"integrity" "sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA=="
7+
"resolved" "https://registry.npmjs.org/@types/node/-/node-15.6.1.tgz"
8+
"version" "15.6.1"
99

10-
ansi-styles@^4.1.0:
11-
version "4.3.0"
12-
resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937"
13-
integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==
10+
"ansi-styles@^4.1.0":
11+
"integrity" "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="
12+
"resolved" "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz"
13+
"version" "4.3.0"
1414
dependencies:
15-
color-convert "^2.0.1"
15+
"color-convert" "^2.0.1"
1616

17-
chalk@^4.1.1:
18-
version "4.1.1"
19-
resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz#c80b3fab28bf6371e6863325eee67e618b77e6ad"
20-
integrity sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==
17+
"chalk@^4.1.1":
18+
"integrity" "sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg=="
19+
"resolved" "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz"
20+
"version" "4.1.1"
2121
dependencies:
22-
ansi-styles "^4.1.0"
23-
supports-color "^7.1.0"
22+
"ansi-styles" "^4.1.0"
23+
"supports-color" "^7.1.0"
2424

25-
color-convert@^2.0.1:
26-
version "2.0.1"
27-
resolved "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
28-
integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==
25+
"color-convert@^2.0.1":
26+
"integrity" "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="
27+
"resolved" "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz"
28+
"version" "2.0.1"
2929
dependencies:
30-
color-name "~1.1.4"
30+
"color-name" "~1.1.4"
3131

32-
color-name@~1.1.4:
33-
version "1.1.4"
34-
resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
35-
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
32+
"color-name@~1.1.4":
33+
"integrity" "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
34+
"resolved" "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz"
35+
"version" "1.1.4"
3636

37-
has-flag@^4.0.0:
38-
version "4.0.0"
39-
resolved "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
40-
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==
37+
"has-flag@^4.0.0":
38+
"integrity" "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
39+
"resolved" "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz"
40+
"version" "4.0.0"
4141

42-
isexe@^2.0.0:
43-
version "2.0.0"
44-
resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
45-
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
42+
"isexe@^2.0.0":
43+
"integrity" "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA="
44+
"resolved" "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz"
45+
"version" "2.0.0"
4646

47-
node-fetch@^2.6.1:
48-
version "2.6.1"
49-
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
50-
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
47+
"node-fetch@^2.6.1":
48+
"integrity" "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
49+
"resolved" "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz"
50+
"version" "2.6.1"
5151

52-
shq@^1.0.2:
53-
version "1.0.2"
54-
resolved "https://registry.npmjs.org/shq/-/shq-1.0.2.tgz#bc3f9ac369100cdd754d45032d987b3b62d32fd0"
55-
integrity sha512-8AvNyHL75DHlkbLmzF7nzTzT2F0qEfSewwxHjH79Ww8S+hGpIZVlf8b0TcdOwv4HqIkOVBInu9n+wqhUSl9Wag==
52+
"shq@^1.0.2":
53+
"integrity" "sha512-8AvNyHL75DHlkbLmzF7nzTzT2F0qEfSewwxHjH79Ww8S+hGpIZVlf8b0TcdOwv4HqIkOVBInu9n+wqhUSl9Wag=="
54+
"resolved" "https://registry.npmjs.org/shq/-/shq-1.0.2.tgz"
55+
"version" "1.0.2"
5656

57-
supports-color@^7.1.0:
58-
version "7.2.0"
59-
resolved "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da"
60-
integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==
57+
"supports-color@^7.1.0":
58+
"integrity" "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw=="
59+
"resolved" "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz"
60+
"version" "7.2.0"
6161
dependencies:
62-
has-flag "^4.0.0"
62+
"has-flag" "^4.0.0"
6363

64-
which@^2.0.2:
65-
version "2.0.2"
66-
resolved "https://registry.npmjs.org/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
67-
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==
64+
"which@^2.0.2":
65+
"integrity" "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA=="
66+
"resolved" "https://registry.npmjs.org/which/-/which-2.0.2.tgz"
67+
"version" "2.0.2"
6868
dependencies:
69-
isexe "^2.0.0"
69+
"isexe" "^2.0.0"
7070

71-
zx@^1.12.0:
72-
version "1.12.0"
73-
resolved "https://registry.npmjs.org/zx/-/zx-1.12.0.tgz#1312166d01fd0445e45eea57438883896a6a8d07"
74-
integrity sha512-JvZxN3QTnZIUF5p9YVpqc/wm6Ghc5yVQd/p53KC0nnSK3RUfeuGMRrOnxJ5c4R4iYwY5F65i4e3BU59JD6svBw==
71+
"zx@^1.12.0":
72+
"integrity" "sha512-JvZxN3QTnZIUF5p9YVpqc/wm6Ghc5yVQd/p53KC0nnSK3RUfeuGMRrOnxJ5c4R4iYwY5F65i4e3BU59JD6svBw=="
73+
"resolved" "https://registry.npmjs.org/zx/-/zx-1.12.0.tgz"
74+
"version" "1.12.0"
7575
dependencies:
7676
"@types/node" "^15.3"
77-
chalk "^4.1.1"
78-
node-fetch "^2.6.1"
79-
shq "^1.0.2"
80-
which "^2.0.2"
77+
"chalk" "^4.1.1"
78+
"node-fetch" "^2.6.1"
79+
"shq" "^1.0.2"
80+
"which" "^2.0.2"

0 commit comments

Comments
 (0)