Skip to content

Commit 0108c30

Browse files
author
youncccat
committed
[Feat::rules] docking plugins to the config of commitlint
1 parent 0ddc72c commit 0108c30

File tree

14 files changed

+78
-85
lines changed

14 files changed

+78
-85
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"devDependencies": {
1313
"@commitlint/cli": "^12.1.4",
1414
"@commitlint/config-conventional": "^12.1.4",
15+
"@commitlint/types": "^12.1.4",
1516
"@types/jest": "^26.0.23",
1617
"jest": "^27.0.1",
1718
"jest-config": "^27.0.1",

packages/commitlint-config-wizardoc/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
"devDependencies": {
1010
"@commitlint/types": "^12.1.4"
1111
},
12-
"dependencies": {}
13-
}
12+
"dependencies": {
13+
"commitlint-plugin-wizardoc-rules": "^1.0.0"
14+
}
15+
}

packages/commitlint-config-wizardoc/src/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from "./constants";
66
import { UserConfig } from "@commitlint/types";
77
import { enumerateValues } from "./utils/enum";
8+
import { plugins } from "commitlint-plugin-wizardoc-rules";
89

910
export const config: UserConfig = {
1011
parserPreset: {
@@ -13,19 +14,18 @@ export const config: UserConfig = {
1314
parserOpts: {
1415
headerPattern: CONVERSION_MATCH_REGEX,
1516
headerCorrespondence: [
17+
LexicalElement.SYMBOL,
1618
LexicalElement.TYPE,
1719
LexicalElement.SCOPE,
1820
LexicalElement.SUBJECT,
1921
],
2022
},
2123
},
24+
...plugins,
2225
rules: {
23-
// 'subject-exclamation-mark': [2, 'never'],
26+
"break-change-prefix": [2, "always"],
2427
"footer-leading-blank": [1, "always"],
2528
"header-max-length": [2, "always", 72],
26-
// 'scope-case': [2, 'always', 'lower-case'],
27-
"subject-case": [2, "never", ["upper-case"] as any],
28-
// 'subject-empty': [2, 'never'],
2929
"subject-full-stop": [2, "never", "."],
3030
"type-empty": [2, "never"],
3131
"scope-empty": [1, "never"],

packages/commitlint-config-wizardoc/src/constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@ export enum LexicalElement {
33
TYPE = "type",
44
SCOPE = "scope",
55
TICKET = "ticket",
6+
SYMBOL = "symbol",
67
}
78

89
export enum CommitType {
910
FEAT = "Feat",
1011
INIT = "Init",
1112
REMOVE = "Remove",
1213
DELETE = "Delete",
14+
UPDATE = "Update",
15+
REFACTOR = "Refactor",
1316
MOVE = "Move",
1417
NEW = "New",
1518
ADD = "Add",
1619
PATCH = "Patch",
1720
FIX = "Fix",
1821
TEST = "Test",
1922
STUB = "Stub",
23+
CHORE = "Chore",
2024
}
2125

22-
export const CONVERSION_MATCH_REGEX = /^\[(\w+?)(?:\:\:(\w*))?\]\s(.*)$/;
26+
export const CONVERSION_MATCH_REGEX = /^(.?)\[(\w+?)(?:\:\:(\w*))?\]\s(.*)$/;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "commitlint-plugin-wizardoc-rules",
33
"version": "1.0.0",
4-
"main": "index.js",
4+
"main": "./dist/index.js",
55
"license": "MIT"
66
}

packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { BREAK_CHANGE_SYMBOL } from "./constants";
2+
import { Commit, Rule, RuleOutcome } from "@commitlint/types";
3+
4+
export type WithSymbol<T> = T & {
5+
symbol: string;
6+
};
7+
8+
export type CommitWithSymbol = WithSymbol<Commit>;
9+
10+
export const breakChangeSymbolRule = (walkData: Commit): RuleOutcome => {
11+
const { symbol } = walkData as CommitWithSymbol;
12+
const isRuleValid = !symbol || symbol === BREAK_CHANGE_SYMBOL;
13+
14+
return [
15+
isRuleValid,
16+
`break change must be symbol with "${BREAK_CHANGE_SYMBOL}" e.g: ${BREAK_CHANGE_SYMBOL}[Type::scope] subject`,
17+
];
18+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const breakChangeSymbol: string = "!";
1+
export const BREAK_CHANGE_SYMBOL = "!";
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
export {};
1+
import { breakChangeSymbolRule } from "./break-change-symbol-rule";
2+
import { Plugin } from "@commitlint/types";
3+
4+
export const plugins: Record<string, Plugin[]> = {
5+
plugins: [
6+
{
7+
rules: {
8+
"break-change-prefix": breakChangeSymbolRule,
9+
},
10+
},
11+
],
12+
};

packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)