From dcda9206f7654d7ac47566d365bc5b31df9f1d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=99=93=E6=99=A8?= <825316969@qq.com> Date: Thu, 27 May 2021 23:14:50 +0800 Subject: [PATCH 1/9] [Add::rules] add breakChangeSymbol rules --- .../src/break-change-symbol-rule-resolver.ts | 25 ++++ .../src/constants.ts | 1 + .../break-change-symbol-rule-resolver.test.ts | 22 ++++ .../src/tests/foo.test.ts | 3 - .../src/typings.ts | 27 +++++ .../commitlint-wizardoc-e2e-tests/yarn.lock | 114 +++++++++--------- 6 files changed, 132 insertions(+), 60 deletions(-) create mode 100644 packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts create mode 100644 packages/commitlint-plugin-wizardoc-rules/src/constants.ts create mode 100644 packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts delete mode 100644 packages/commitlint-plugin-wizardoc-rules/src/tests/foo.test.ts create mode 100644 packages/commitlint-plugin-wizardoc-rules/src/typings.ts diff --git a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts new file mode 100644 index 0000000..2069808 --- /dev/null +++ b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts @@ -0,0 +1,25 @@ +import { RuleResolver } from "./typings"; +import { breakChangeSymbol } from "./constants"; + +const breakChangeSymbolRuleResolver: RuleResolver = ( + parsed, + _when, + value = breakChangeSymbol +) => { + const rawCommitMessage = parsed.raw; + if (!rawCommitMessage) return [false, "Commit message should not be empty"]; + + let isRuleValid = false; + + const findedBreakChangeSymbol: string = rawCommitMessage.split("[")[0]; + + // 查找[ 前一项 + if (!findedBreakChangeSymbol || findedBreakChangeSymbol === value) + isRuleValid = true; + + return [ + isRuleValid, + `break change must be symbol with "${value}" e.g: ${value}[Type::scope] subject`, + ]; +}; +export default breakChangeSymbolRuleResolver; diff --git a/packages/commitlint-plugin-wizardoc-rules/src/constants.ts b/packages/commitlint-plugin-wizardoc-rules/src/constants.ts new file mode 100644 index 0000000..bec83c6 --- /dev/null +++ b/packages/commitlint-plugin-wizardoc-rules/src/constants.ts @@ -0,0 +1 @@ +export const breakChangeSymbol: string = "!"; diff --git a/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts b/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts new file mode 100644 index 0000000..2c302ec --- /dev/null +++ b/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts @@ -0,0 +1,22 @@ +import breakChangeSymbolRuleResolver from "../break-change-symbol-rule-resolver"; + +describe("breakChangeSymbolRuleResolver", () => { + it("should return a error response if breakChangeSymbol is not !", () => { + const parsed = { + raw: "$[Type::scope] subject", + }; + expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(false); + }); + it("should return a success response if no breakChangeSymbol", () => { + const parsed = { + raw: "[Type::scope] subject", + }; + expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(true); + }); + it("should return a success response if breakChangeSymbol is !", () => { + const parsed = { + raw: "![Type::scope] subject", + }; + expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(true); + }); +}); diff --git a/packages/commitlint-plugin-wizardoc-rules/src/tests/foo.test.ts b/packages/commitlint-plugin-wizardoc-rules/src/tests/foo.test.ts deleted file mode 100644 index d557277..0000000 --- a/packages/commitlint-plugin-wizardoc-rules/src/tests/foo.test.ts +++ /dev/null @@ -1,3 +0,0 @@ -describe("", () => { - it("aaaa", () => expect(9).toEqual(9)); -}); diff --git a/packages/commitlint-plugin-wizardoc-rules/src/typings.ts b/packages/commitlint-plugin-wizardoc-rules/src/typings.ts new file mode 100644 index 0000000..20d7ddf --- /dev/null +++ b/packages/commitlint-plugin-wizardoc-rules/src/typings.ts @@ -0,0 +1,27 @@ +export type RuleResolver = ( + parsed: Partial<{ + type: string; + scope: string; + subject: string; + merge: string; + header: string; + body: string; + footer: string; + notes: string[]; + references: string[]; + mentions: string[]; + revert: string; + raw: string; + }>, + when?: string, + value?: string | number | boolean | (string | number)[] +) => (string | boolean)[]; + +export interface CommitlintPlugin { + rules: { + [key: string]: RuleResolver; + }; +} +declare const commitlintPlugin: CommitlintPlugin; + +export default commitlintPlugin; diff --git a/packages/commitlint-wizardoc-e2e-tests/yarn.lock b/packages/commitlint-wizardoc-e2e-tests/yarn.lock index 1ffe11d..f75519e 100644 --- a/packages/commitlint-wizardoc-e2e-tests/yarn.lock +++ b/packages/commitlint-wizardoc-e2e-tests/yarn.lock @@ -3,78 +3,78 @@ "@types/node@^15.3": - version "15.6.1" - resolved "https://registry.npmjs.org/@types/node/-/node-15.6.1.tgz#32d43390d5c62c5b6ec486a9bc9c59544de39a08" - integrity sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA== + "integrity" "sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA==" + "resolved" "https://registry.npmjs.org/@types/node/-/node-15.6.1.tgz" + "version" "15.6.1" -ansi-styles@^4.1.0: - version "4.3.0" - resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" - integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== +"ansi-styles@^4.1.0": + "integrity" "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==" + "resolved" "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz" + "version" "4.3.0" dependencies: - color-convert "^2.0.1" + "color-convert" "^2.0.1" -chalk@^4.1.1: - version "4.1.1" - resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz#c80b3fab28bf6371e6863325eee67e618b77e6ad" - integrity sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg== +"chalk@^4.1.1": + "integrity" "sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==" + "resolved" "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz" + "version" "4.1.1" dependencies: - ansi-styles "^4.1.0" - supports-color "^7.1.0" + "ansi-styles" "^4.1.0" + "supports-color" "^7.1.0" -color-convert@^2.0.1: - version "2.0.1" - resolved "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" - integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== +"color-convert@^2.0.1": + "integrity" "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==" + "resolved" "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz" + "version" "2.0.1" dependencies: - color-name "~1.1.4" + "color-name" "~1.1.4" -color-name@~1.1.4: - version "1.1.4" - resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" - integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== +"color-name@~1.1.4": + "integrity" "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + "resolved" "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz" + "version" "1.1.4" -has-flag@^4.0.0: - version "4.0.0" - resolved "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" - integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== +"has-flag@^4.0.0": + "integrity" "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + "resolved" "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz" + "version" "4.0.0" -isexe@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" - integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= +"isexe@^2.0.0": + "integrity" "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + "resolved" "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz" + "version" "2.0.0" -node-fetch@^2.6.1: - version "2.6.1" - resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" - integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== +"node-fetch@^2.6.1": + "integrity" "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + "resolved" "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz" + "version" "2.6.1" -shq@^1.0.2: - version "1.0.2" - resolved "https://registry.npmjs.org/shq/-/shq-1.0.2.tgz#bc3f9ac369100cdd754d45032d987b3b62d32fd0" - integrity sha512-8AvNyHL75DHlkbLmzF7nzTzT2F0qEfSewwxHjH79Ww8S+hGpIZVlf8b0TcdOwv4HqIkOVBInu9n+wqhUSl9Wag== +"shq@^1.0.2": + "integrity" "sha512-8AvNyHL75DHlkbLmzF7nzTzT2F0qEfSewwxHjH79Ww8S+hGpIZVlf8b0TcdOwv4HqIkOVBInu9n+wqhUSl9Wag==" + "resolved" "https://registry.npmjs.org/shq/-/shq-1.0.2.tgz" + "version" "1.0.2" -supports-color@^7.1.0: - version "7.2.0" - resolved "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" - integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== +"supports-color@^7.1.0": + "integrity" "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==" + "resolved" "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz" + "version" "7.2.0" dependencies: - has-flag "^4.0.0" + "has-flag" "^4.0.0" -which@^2.0.2: - version "2.0.2" - resolved "https://registry.npmjs.org/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" - integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== +"which@^2.0.2": + "integrity" "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==" + "resolved" "https://registry.npmjs.org/which/-/which-2.0.2.tgz" + "version" "2.0.2" dependencies: - isexe "^2.0.0" + "isexe" "^2.0.0" -zx@^1.12.0: - version "1.12.0" - resolved "https://registry.npmjs.org/zx/-/zx-1.12.0.tgz#1312166d01fd0445e45eea57438883896a6a8d07" - integrity sha512-JvZxN3QTnZIUF5p9YVpqc/wm6Ghc5yVQd/p53KC0nnSK3RUfeuGMRrOnxJ5c4R4iYwY5F65i4e3BU59JD6svBw== +"zx@^1.12.0": + "integrity" "sha512-JvZxN3QTnZIUF5p9YVpqc/wm6Ghc5yVQd/p53KC0nnSK3RUfeuGMRrOnxJ5c4R4iYwY5F65i4e3BU59JD6svBw==" + "resolved" "https://registry.npmjs.org/zx/-/zx-1.12.0.tgz" + "version" "1.12.0" dependencies: "@types/node" "^15.3" - chalk "^4.1.1" - node-fetch "^2.6.1" - shq "^1.0.2" - which "^2.0.2" + "chalk" "^4.1.1" + "node-fetch" "^2.6.1" + "shq" "^1.0.2" + "which" "^2.0.2" From cbcf42331077c47fbe4db1768e7b2ce4a0717e1c Mon Sep 17 00:00:00 2001 From: youncccat <1306036576@qq.com> Date: Fri, 28 May 2021 02:29:17 +0800 Subject: [PATCH 2/9] [Feat::rules] docking plugins to the config of commitlint --- package.json | 1 + .../commitlint-config-wizardoc/package.json | 6 +++-- .../commitlint-config-wizardoc/src/config.ts | 8 +++--- .../src/constants.ts | 6 ++++- .../package.json | 2 +- .../src/break-change-symbol-rule-resolver.ts | 25 ----------------- .../src/break-change-symbol-rule.ts | 18 +++++++++++++ .../src/constants.ts | 2 +- .../src/index.ts | 13 ++++++++- .../break-change-symbol-rule-resolver.test.ts | 22 --------------- .../tests/break-change-symbol-rule.test.ts | 27 +++++++++++++++++++ .../src/typings.ts | 27 ------------------- .../tsconfig.json | 4 +++ yarn.lock | 2 +- 14 files changed, 78 insertions(+), 85 deletions(-) delete mode 100644 packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts create mode 100644 packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts delete mode 100644 packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts create mode 100644 packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule.test.ts delete mode 100644 packages/commitlint-plugin-wizardoc-rules/src/typings.ts diff --git a/package.json b/package.json index b5f6fe4..596dd8b 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "devDependencies": { "@commitlint/cli": "^12.1.4", "@commitlint/config-conventional": "^12.1.4", + "@commitlint/types": "^12.1.4", "@types/jest": "^26.0.23", "jest": "^27.0.1", "jest-config": "^27.0.1", diff --git a/packages/commitlint-config-wizardoc/package.json b/packages/commitlint-config-wizardoc/package.json index e652bc1..2f68b56 100644 --- a/packages/commitlint-config-wizardoc/package.json +++ b/packages/commitlint-config-wizardoc/package.json @@ -9,5 +9,7 @@ "devDependencies": { "@commitlint/types": "^12.1.4" }, - "dependencies": {} -} \ No newline at end of file + "dependencies": { + "commitlint-plugin-wizardoc-rules": "^1.0.0" + } +} diff --git a/packages/commitlint-config-wizardoc/src/config.ts b/packages/commitlint-config-wizardoc/src/config.ts index 574a4d8..588d78d 100644 --- a/packages/commitlint-config-wizardoc/src/config.ts +++ b/packages/commitlint-config-wizardoc/src/config.ts @@ -5,6 +5,7 @@ import { } from "./constants"; import { UserConfig } from "@commitlint/types"; import { enumerateValues } from "./utils/enum"; +import { plugins } from "commitlint-plugin-wizardoc-rules"; export const config: UserConfig = { parserPreset: { @@ -13,19 +14,18 @@ export const config: UserConfig = { parserOpts: { headerPattern: CONVERSION_MATCH_REGEX, headerCorrespondence: [ + LexicalElement.SYMBOL, LexicalElement.TYPE, LexicalElement.SCOPE, LexicalElement.SUBJECT, ], }, }, + ...plugins, rules: { - // 'subject-exclamation-mark': [2, 'never'], + "break-change-prefix": [2, "always"], "footer-leading-blank": [1, "always"], "header-max-length": [2, "always", 72], - // 'scope-case': [2, 'always', 'lower-case'], - "subject-case": [2, "never", ["upper-case"] as any], - // 'subject-empty': [2, 'never'], "subject-full-stop": [2, "never", "."], "type-empty": [2, "never"], "scope-empty": [1, "never"], diff --git a/packages/commitlint-config-wizardoc/src/constants.ts b/packages/commitlint-config-wizardoc/src/constants.ts index 06eb537..9be4791 100644 --- a/packages/commitlint-config-wizardoc/src/constants.ts +++ b/packages/commitlint-config-wizardoc/src/constants.ts @@ -3,6 +3,7 @@ export enum LexicalElement { TYPE = "type", SCOPE = "scope", TICKET = "ticket", + SYMBOL = "symbol", } export enum CommitType { @@ -10,6 +11,8 @@ export enum CommitType { INIT = "Init", REMOVE = "Remove", DELETE = "Delete", + UPDATE = "Update", + REFACTOR = "Refactor", MOVE = "Move", NEW = "New", ADD = "Add", @@ -17,6 +20,7 @@ export enum CommitType { FIX = "Fix", TEST = "Test", STUB = "Stub", + CHORE = "Chore", } -export const CONVERSION_MATCH_REGEX = /^\[(\w+?)(?:\:\:(\w*))?\]\s(.*)$/; +export const CONVERSION_MATCH_REGEX = /^(.?)\[(\w+?)(?:\:\:(\w*))?\]\s(.*)$/; diff --git a/packages/commitlint-plugin-wizardoc-rules/package.json b/packages/commitlint-plugin-wizardoc-rules/package.json index 953bbf5..19afa57 100644 --- a/packages/commitlint-plugin-wizardoc-rules/package.json +++ b/packages/commitlint-plugin-wizardoc-rules/package.json @@ -1,6 +1,6 @@ { "name": "commitlint-plugin-wizardoc-rules", "version": "1.0.0", - "main": "index.js", + "main": "./dist/index.js", "license": "MIT" } \ No newline at end of file diff --git a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts deleted file mode 100644 index 2069808..0000000 --- a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { RuleResolver } from "./typings"; -import { breakChangeSymbol } from "./constants"; - -const breakChangeSymbolRuleResolver: RuleResolver = ( - parsed, - _when, - value = breakChangeSymbol -) => { - const rawCommitMessage = parsed.raw; - if (!rawCommitMessage) return [false, "Commit message should not be empty"]; - - let isRuleValid = false; - - const findedBreakChangeSymbol: string = rawCommitMessage.split("[")[0]; - - // 查找[ 前一项 - if (!findedBreakChangeSymbol || findedBreakChangeSymbol === value) - isRuleValid = true; - - return [ - isRuleValid, - `break change must be symbol with "${value}" e.g: ${value}[Type::scope] subject`, - ]; -}; -export default breakChangeSymbolRuleResolver; diff --git a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts new file mode 100644 index 0000000..ff9aa39 --- /dev/null +++ b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts @@ -0,0 +1,18 @@ +import { BREAK_CHANGE_SYMBOL } from "./constants"; +import { Commit, Rule, RuleOutcome } from "@commitlint/types"; + +export type WithSymbol = T & { + symbol: string; +}; + +export type CommitWithSymbol = WithSymbol; + +export const breakChangeSymbolRule = (walkData: Commit): RuleOutcome => { + const { symbol } = walkData as CommitWithSymbol; + const isRuleValid = !symbol || symbol === BREAK_CHANGE_SYMBOL; + + return [ + isRuleValid, + `break change must be symbol with "${BREAK_CHANGE_SYMBOL}" e.g: ${BREAK_CHANGE_SYMBOL}[Type::scope] subject`, + ]; +}; diff --git a/packages/commitlint-plugin-wizardoc-rules/src/constants.ts b/packages/commitlint-plugin-wizardoc-rules/src/constants.ts index bec83c6..9b5556b 100644 --- a/packages/commitlint-plugin-wizardoc-rules/src/constants.ts +++ b/packages/commitlint-plugin-wizardoc-rules/src/constants.ts @@ -1 +1 @@ -export const breakChangeSymbol: string = "!"; +export const BREAK_CHANGE_SYMBOL = "!"; diff --git a/packages/commitlint-plugin-wizardoc-rules/src/index.ts b/packages/commitlint-plugin-wizardoc-rules/src/index.ts index cb0ff5c..a1e4575 100644 --- a/packages/commitlint-plugin-wizardoc-rules/src/index.ts +++ b/packages/commitlint-plugin-wizardoc-rules/src/index.ts @@ -1 +1,12 @@ -export {}; +import { breakChangeSymbolRule } from "./break-change-symbol-rule"; +import { Plugin } from "@commitlint/types"; + +export const plugins: Record = { + plugins: [ + { + rules: { + "break-change-prefix": breakChangeSymbolRule, + }, + }, + ], +}; diff --git a/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts b/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts deleted file mode 100644 index 2c302ec..0000000 --- a/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -import breakChangeSymbolRuleResolver from "../break-change-symbol-rule-resolver"; - -describe("breakChangeSymbolRuleResolver", () => { - it("should return a error response if breakChangeSymbol is not !", () => { - const parsed = { - raw: "$[Type::scope] subject", - }; - expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(false); - }); - it("should return a success response if no breakChangeSymbol", () => { - const parsed = { - raw: "[Type::scope] subject", - }; - expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(true); - }); - it("should return a success response if breakChangeSymbol is !", () => { - const parsed = { - raw: "![Type::scope] subject", - }; - expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(true); - }); -}); diff --git a/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule.test.ts b/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule.test.ts new file mode 100644 index 0000000..222094d --- /dev/null +++ b/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule.test.ts @@ -0,0 +1,27 @@ +import { Commit, RuleOutcome } from "@commitlint/types"; +import { breakChangeSymbolRule, WithSymbol } from "../break-change-symbol-rule"; +import { BREAK_CHANGE_SYMBOL } from "../constants"; + +const walkData = { + symbol: BREAK_CHANGE_SYMBOL, +} as unknown as WithSymbol; + +const updateWalkData = (symbol: string) => (walkData.symbol = symbol); +const getIsValid = ([isValid]: RuleOutcome) => isValid; + +describe("breakChangeSymbolRule", () => { + it("should return a error response if breakChangeSymbol is not !", () => { + updateWalkData("@"); + expect(getIsValid(breakChangeSymbolRule(walkData))).toEqual(false); + }); + + it("should return a success response if no breakChangeSymbol", () => { + updateWalkData(""); + expect(getIsValid(breakChangeSymbolRule(walkData))).toEqual(true); + }); + + it("should return a success response if breakChangeSymbol is !", () => { + updateWalkData(BREAK_CHANGE_SYMBOL); + expect(getIsValid(breakChangeSymbolRule(walkData))).toEqual(true); + }); +}); diff --git a/packages/commitlint-plugin-wizardoc-rules/src/typings.ts b/packages/commitlint-plugin-wizardoc-rules/src/typings.ts deleted file mode 100644 index 20d7ddf..0000000 --- a/packages/commitlint-plugin-wizardoc-rules/src/typings.ts +++ /dev/null @@ -1,27 +0,0 @@ -export type RuleResolver = ( - parsed: Partial<{ - type: string; - scope: string; - subject: string; - merge: string; - header: string; - body: string; - footer: string; - notes: string[]; - references: string[]; - mentions: string[]; - revert: string; - raw: string; - }>, - when?: string, - value?: string | number | boolean | (string | number)[] -) => (string | boolean)[]; - -export interface CommitlintPlugin { - rules: { - [key: string]: RuleResolver; - }; -} -declare const commitlintPlugin: CommitlintPlugin; - -export default commitlintPlugin; diff --git a/packages/commitlint-plugin-wizardoc-rules/tsconfig.json b/packages/commitlint-plugin-wizardoc-rules/tsconfig.json index 0ff89db..5f7bc6e 100644 --- a/packages/commitlint-plugin-wizardoc-rules/tsconfig.json +++ b/packages/commitlint-plugin-wizardoc-rules/tsconfig.json @@ -1,5 +1,9 @@ { "extends": "../../tsconfig.base", "include": ["src"], + "compilerOptions": { + "rootDir": "src", + "outDir": "dist", + }, "exclude": ["node_modules"] } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index c3cec69..19e2b77 100644 --- a/yarn.lock +++ b/yarn.lock @@ -426,7 +426,7 @@ "@commitlint/types@^12.1.4": version "12.1.4" - resolved "https://registry.npmjs.org/@commitlint/types/-/types-12.1.4.tgz" + resolved "https://registry.npmjs.org/@commitlint/types/-/types-12.1.4.tgz#9618a5dc8991fb58e6de6ed89d7bf712fa74ba7e" integrity sha512-KRIjdnWNUx6ywz+SJvjmNCbQKcKP6KArhjZhY2l+CWKxak0d77SOjggkMwFTiSgLODOwmuLTbarR2ZfWPiPMlw== dependencies: chalk "^4.0.0" From ae35aaddb89c5f51d626c791229cb3eaf6b86904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=99=93=E6=99=A8?= <825316969@qq.com> Date: Sat, 29 May 2021 00:33:59 +0800 Subject: [PATCH 3/9] [Chore::relues] break change symbol rule add parameters --- .../src/break-change-symbol-rule.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts index ff9aa39..4cc56f6 100644 --- a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts +++ b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts @@ -1,5 +1,10 @@ import { BREAK_CHANGE_SYMBOL } from "./constants"; -import { Commit, Rule, RuleOutcome } from "@commitlint/types"; +import { + Commit, + Rule, + RuleOutcome, + RuleConfigCondition, +} from "@commitlint/types"; export type WithSymbol = T & { symbol: string; @@ -7,12 +12,16 @@ export type WithSymbol = T & { export type CommitWithSymbol = WithSymbol; -export const breakChangeSymbolRule = (walkData: Commit): RuleOutcome => { +export const breakChangeSymbolRule = ( + walkData: Commit, + when?: RuleConfigCondition, + value: string = BREAK_CHANGE_SYMBOL +): RuleOutcome => { const { symbol } = walkData as CommitWithSymbol; - const isRuleValid = !symbol || symbol === BREAK_CHANGE_SYMBOL; + const isRuleValid = !symbol || symbol === value; return [ isRuleValid, - `break change must be symbol with "${BREAK_CHANGE_SYMBOL}" e.g: ${BREAK_CHANGE_SYMBOL}[Type::scope] subject`, + `break change must be symbol with "${value}" e.g: ${value}[Type::scope] subject`, ]; }; From 3d32a9d6acd3f34d89ca2dde20c251e1a27d46cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=99=93=E6=99=A8?= <825316969@qq.com> Date: Thu, 27 May 2021 23:14:50 +0800 Subject: [PATCH 4/9] [Add::rules] add breakChangeSymbol rules --- .../src/break-change-symbol-rule-resolver.ts | 25 +++++++++++++++++ .../break-change-symbol-rule-resolver.test.ts | 22 +++++++++++++++ .../src/typings.ts | 27 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts create mode 100644 packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts create mode 100644 packages/commitlint-plugin-wizardoc-rules/src/typings.ts diff --git a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts new file mode 100644 index 0000000..2069808 --- /dev/null +++ b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts @@ -0,0 +1,25 @@ +import { RuleResolver } from "./typings"; +import { breakChangeSymbol } from "./constants"; + +const breakChangeSymbolRuleResolver: RuleResolver = ( + parsed, + _when, + value = breakChangeSymbol +) => { + const rawCommitMessage = parsed.raw; + if (!rawCommitMessage) return [false, "Commit message should not be empty"]; + + let isRuleValid = false; + + const findedBreakChangeSymbol: string = rawCommitMessage.split("[")[0]; + + // 查找[ 前一项 + if (!findedBreakChangeSymbol || findedBreakChangeSymbol === value) + isRuleValid = true; + + return [ + isRuleValid, + `break change must be symbol with "${value}" e.g: ${value}[Type::scope] subject`, + ]; +}; +export default breakChangeSymbolRuleResolver; diff --git a/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts b/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts new file mode 100644 index 0000000..2c302ec --- /dev/null +++ b/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts @@ -0,0 +1,22 @@ +import breakChangeSymbolRuleResolver from "../break-change-symbol-rule-resolver"; + +describe("breakChangeSymbolRuleResolver", () => { + it("should return a error response if breakChangeSymbol is not !", () => { + const parsed = { + raw: "$[Type::scope] subject", + }; + expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(false); + }); + it("should return a success response if no breakChangeSymbol", () => { + const parsed = { + raw: "[Type::scope] subject", + }; + expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(true); + }); + it("should return a success response if breakChangeSymbol is !", () => { + const parsed = { + raw: "![Type::scope] subject", + }; + expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(true); + }); +}); diff --git a/packages/commitlint-plugin-wizardoc-rules/src/typings.ts b/packages/commitlint-plugin-wizardoc-rules/src/typings.ts new file mode 100644 index 0000000..20d7ddf --- /dev/null +++ b/packages/commitlint-plugin-wizardoc-rules/src/typings.ts @@ -0,0 +1,27 @@ +export type RuleResolver = ( + parsed: Partial<{ + type: string; + scope: string; + subject: string; + merge: string; + header: string; + body: string; + footer: string; + notes: string[]; + references: string[]; + mentions: string[]; + revert: string; + raw: string; + }>, + when?: string, + value?: string | number | boolean | (string | number)[] +) => (string | boolean)[]; + +export interface CommitlintPlugin { + rules: { + [key: string]: RuleResolver; + }; +} +declare const commitlintPlugin: CommitlintPlugin; + +export default commitlintPlugin; From 8bd94913c5fe243770d70843b299bda4af65571a Mon Sep 17 00:00:00 2001 From: youncccat <1306036576@qq.com> Date: Fri, 28 May 2021 02:29:17 +0800 Subject: [PATCH 5/9] [Feat::rules] docking plugins to the config of commitlint --- .../src/break-change-symbol-rule-resolver.ts | 25 ----------------- .../break-change-symbol-rule-resolver.test.ts | 22 --------------- .../src/typings.ts | 27 ------------------- 3 files changed, 74 deletions(-) delete mode 100644 packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts delete mode 100644 packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts delete mode 100644 packages/commitlint-plugin-wizardoc-rules/src/typings.ts diff --git a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts deleted file mode 100644 index 2069808..0000000 --- a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule-resolver.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { RuleResolver } from "./typings"; -import { breakChangeSymbol } from "./constants"; - -const breakChangeSymbolRuleResolver: RuleResolver = ( - parsed, - _when, - value = breakChangeSymbol -) => { - const rawCommitMessage = parsed.raw; - if (!rawCommitMessage) return [false, "Commit message should not be empty"]; - - let isRuleValid = false; - - const findedBreakChangeSymbol: string = rawCommitMessage.split("[")[0]; - - // 查找[ 前一项 - if (!findedBreakChangeSymbol || findedBreakChangeSymbol === value) - isRuleValid = true; - - return [ - isRuleValid, - `break change must be symbol with "${value}" e.g: ${value}[Type::scope] subject`, - ]; -}; -export default breakChangeSymbolRuleResolver; diff --git a/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts b/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts deleted file mode 100644 index 2c302ec..0000000 --- a/packages/commitlint-plugin-wizardoc-rules/src/tests/break-change-symbol-rule-resolver.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -import breakChangeSymbolRuleResolver from "../break-change-symbol-rule-resolver"; - -describe("breakChangeSymbolRuleResolver", () => { - it("should return a error response if breakChangeSymbol is not !", () => { - const parsed = { - raw: "$[Type::scope] subject", - }; - expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(false); - }); - it("should return a success response if no breakChangeSymbol", () => { - const parsed = { - raw: "[Type::scope] subject", - }; - expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(true); - }); - it("should return a success response if breakChangeSymbol is !", () => { - const parsed = { - raw: "![Type::scope] subject", - }; - expect(breakChangeSymbolRuleResolver(parsed)[0]).toEqual(true); - }); -}); diff --git a/packages/commitlint-plugin-wizardoc-rules/src/typings.ts b/packages/commitlint-plugin-wizardoc-rules/src/typings.ts deleted file mode 100644 index 20d7ddf..0000000 --- a/packages/commitlint-plugin-wizardoc-rules/src/typings.ts +++ /dev/null @@ -1,27 +0,0 @@ -export type RuleResolver = ( - parsed: Partial<{ - type: string; - scope: string; - subject: string; - merge: string; - header: string; - body: string; - footer: string; - notes: string[]; - references: string[]; - mentions: string[]; - revert: string; - raw: string; - }>, - when?: string, - value?: string | number | boolean | (string | number)[] -) => (string | boolean)[]; - -export interface CommitlintPlugin { - rules: { - [key: string]: RuleResolver; - }; -} -declare const commitlintPlugin: CommitlintPlugin; - -export default commitlintPlugin; From ab2fcc5a5958288ec4557813d8c7166ab1142c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=99=93=E6=99=A8?= <825316969@qq.com> Date: Sat, 29 May 2021 00:33:59 +0800 Subject: [PATCH 6/9] [Chore::relues] break change symbol rule add parameters --- .../src/break-change-symbol-rule.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts index ff9aa39..4cc56f6 100644 --- a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts +++ b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts @@ -1,5 +1,10 @@ import { BREAK_CHANGE_SYMBOL } from "./constants"; -import { Commit, Rule, RuleOutcome } from "@commitlint/types"; +import { + Commit, + Rule, + RuleOutcome, + RuleConfigCondition, +} from "@commitlint/types"; export type WithSymbol = T & { symbol: string; @@ -7,12 +12,16 @@ export type WithSymbol = T & { export type CommitWithSymbol = WithSymbol; -export const breakChangeSymbolRule = (walkData: Commit): RuleOutcome => { +export const breakChangeSymbolRule = ( + walkData: Commit, + when?: RuleConfigCondition, + value: string = BREAK_CHANGE_SYMBOL +): RuleOutcome => { const { symbol } = walkData as CommitWithSymbol; - const isRuleValid = !symbol || symbol === BREAK_CHANGE_SYMBOL; + const isRuleValid = !symbol || symbol === value; return [ isRuleValid, - `break change must be symbol with "${BREAK_CHANGE_SYMBOL}" e.g: ${BREAK_CHANGE_SYMBOL}[Type::scope] subject`, + `break change must be symbol with "${value}" e.g: ${value}[Type::scope] subject`, ]; }; From 477ca2e62ca92aa84c9549897317ed7d77c1cb26 Mon Sep 17 00:00:00 2001 From: blues <37956833+z825316969@users.noreply.github.com> Date: Fri, 28 May 2021 02:40:17 +0800 Subject: [PATCH 7/9] [WIP] add breakChangeSymbol rule (#2) * [Add::rules] add breakChangeSymbol rules * [Feat::rules] docking plugins to the config of commitlint Co-authored-by: youncccat <1306036576@qq.com> --- .../src/break-change-symbol-rule.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts index 4cc56f6..1bd809f 100644 --- a/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts +++ b/packages/commitlint-plugin-wizardoc-rules/src/break-change-symbol-rule.ts @@ -1,10 +1,5 @@ import { BREAK_CHANGE_SYMBOL } from "./constants"; -import { - Commit, - Rule, - RuleOutcome, - RuleConfigCondition, -} from "@commitlint/types"; +import { Commit, RuleOutcome, RuleConfigCondition } from "@commitlint/types"; export type WithSymbol = T & { symbol: string; @@ -14,7 +9,7 @@ export type CommitWithSymbol = WithSymbol; export const breakChangeSymbolRule = ( walkData: Commit, - when?: RuleConfigCondition, + _when?: RuleConfigCondition, value: string = BREAK_CHANGE_SYMBOL ): RuleOutcome => { const { symbol } = walkData as CommitWithSymbol; From 93ba8f56f98b0bffc0c3b10be6eb8d4cd5edc282 Mon Sep 17 00:00:00 2001 From: youncccat <1306036576@qq.com> Date: Sat, 29 May 2021 01:09:21 +0800 Subject: [PATCH 8/9] [Feat] add utils for using $ to exec --- packages/commitlint-wizardoc-e2e-tests/package.json | 4 +++- packages/commitlint-wizardoc-e2e-tests/src/utils/shell.ts | 6 ++++++ tsconfig.base.json | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 packages/commitlint-wizardoc-e2e-tests/src/utils/shell.ts diff --git a/packages/commitlint-wizardoc-e2e-tests/package.json b/packages/commitlint-wizardoc-e2e-tests/package.json index 176b5a3..4b489ee 100644 --- a/packages/commitlint-wizardoc-e2e-tests/package.json +++ b/packages/commitlint-wizardoc-e2e-tests/package.json @@ -4,9 +4,11 @@ "main": "index.js", "license": "MIT", "devDependencies": { + "@types/shelljs": "^0.8.8", "zx": "^1.12.0" }, "dependencies": { - "commitlint-config-wizardoc": "^1.0.0" + "commitlint-config-wizardoc": "^1.0.0", + "shelljs": "^0.8.4" } } diff --git a/packages/commitlint-wizardoc-e2e-tests/src/utils/shell.ts b/packages/commitlint-wizardoc-e2e-tests/src/utils/shell.ts new file mode 100644 index 0000000..040d882 --- /dev/null +++ b/packages/commitlint-wizardoc-e2e-tests/src/utils/shell.ts @@ -0,0 +1,6 @@ +import shell from "shelljs"; + +export const $ = (pieces: TemplateStringsArray, args?: unknown[]) => + shell.exec( + pieces.reduce((pre, cur, i) => pre + cur + ((args ?? [])[i] ?? ""), "") + ); diff --git a/tsconfig.base.json b/tsconfig.base.json index df5acd0..3d153d5 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -8,6 +8,7 @@ "declaration": true, "skipLibCheck": true, "skipDefaultLibCheck": true, - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "esModuleInterop": true } } \ No newline at end of file From 34066380e30f7b0716843f8f41d170936a64e5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=99=93=E6=99=A8?= <825316969@qq.com> Date: Sat, 29 May 2021 01:47:35 +0800 Subject: [PATCH 9/9] [Test::e2e] e2e test case --- .../commitlint-config-wizardoc/src/config.ts | 2 +- .../package.json | 3 +- .../src/tests/index.test.ts | 50 ++++ .../src/utils/shell.ts | 8 +- .../commitlint-wizardoc-e2e-tests/yarn.lock | 218 ++++++++++++------ 5 files changed, 207 insertions(+), 74 deletions(-) create mode 100644 packages/commitlint-wizardoc-e2e-tests/src/tests/index.test.ts diff --git a/packages/commitlint-config-wizardoc/src/config.ts b/packages/commitlint-config-wizardoc/src/config.ts index 588d78d..2468454 100644 --- a/packages/commitlint-config-wizardoc/src/config.ts +++ b/packages/commitlint-config-wizardoc/src/config.ts @@ -23,7 +23,7 @@ export const config: UserConfig = { }, ...plugins, rules: { - "break-change-prefix": [2, "always"], + "break-change-prefix": [2, "always", "#"], "footer-leading-blank": [1, "always"], "header-max-length": [2, "always", 72], "subject-full-stop": [2, "never", "."], diff --git a/packages/commitlint-wizardoc-e2e-tests/package.json b/packages/commitlint-wizardoc-e2e-tests/package.json index 4b489ee..8e36bc1 100644 --- a/packages/commitlint-wizardoc-e2e-tests/package.json +++ b/packages/commitlint-wizardoc-e2e-tests/package.json @@ -4,8 +4,7 @@ "main": "index.js", "license": "MIT", "devDependencies": { - "@types/shelljs": "^0.8.8", - "zx": "^1.12.0" + "@types/shelljs": "^0.8.8" }, "dependencies": { "commitlint-config-wizardoc": "^1.0.0", diff --git a/packages/commitlint-wizardoc-e2e-tests/src/tests/index.test.ts b/packages/commitlint-wizardoc-e2e-tests/src/tests/index.test.ts new file mode 100644 index 0000000..578acd3 --- /dev/null +++ b/packages/commitlint-wizardoc-e2e-tests/src/tests/index.test.ts @@ -0,0 +1,50 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { $ } from "../utils/shell"; + +const SUCCESS_SIGNAL = 0; + +describe("commitlintPluginRuleTests", () => { + const successfulCase = "![Add::scope] subject"; + + it("success provided commitlint config", () => { + const res = $`echo "${successfulCase}" | npx commitlint`; + + expect(res.code).toEqual(SUCCESS_SIGNAL); + }); + + it("success provided commitlint config", () => { + const res = $`echo "${successfulCase}" | npx commitlint`; + + expect(res.code).toEqual(SUCCESS_SIGNAL); + }); + + it("type fail provided commitlint config", () => { + const res = $`echo ![add::scope] subject | npx commitlint`; + + expect(res.code).not.toEqual(SUCCESS_SIGNAL); + }); + + it("scope fail provided commitlint config", () => { + const res = $`echo @[add@scope] subjectFail | npx commitlint`; + + expect(res.code).not.toEqual(SUCCESS_SIGNAL); + }); + + it("symbol fail provided commitlint config", () => { + const res = $`echo @[add::scope] subject | npx commitlint`; + + expect(res.code).not.toEqual(SUCCESS_SIGNAL); + }); + + it("subject fail provided commitlint config", () => { + const res = $`echo @[add::scope] subject_fail | npx commitlint`; + + expect(res.code).not.toEqual(SUCCESS_SIGNAL); + }); + + it("subject fail provided commitlint config", () => { + const res = $`echo @[add::scope] subjectFail | npx commitlint`; + + expect(res.code).not.toEqual(SUCCESS_SIGNAL); + }); +}); diff --git a/packages/commitlint-wizardoc-e2e-tests/src/utils/shell.ts b/packages/commitlint-wizardoc-e2e-tests/src/utils/shell.ts index 040d882..6581cac 100644 --- a/packages/commitlint-wizardoc-e2e-tests/src/utils/shell.ts +++ b/packages/commitlint-wizardoc-e2e-tests/src/utils/shell.ts @@ -1,6 +1,4 @@ -import shell from "shelljs"; +import { exec } from "shelljs"; -export const $ = (pieces: TemplateStringsArray, args?: unknown[]) => - shell.exec( - pieces.reduce((pre, cur, i) => pre + cur + ((args ?? [])[i] ?? ""), "") - ); +export const $ = (pieces: TemplateStringsArray, ...args: unknown[]) => + exec(pieces.reduce((pre, cur, i) => pre + cur + ((args ?? [])[i] ?? ""), "")); diff --git a/packages/commitlint-wizardoc-e2e-tests/yarn.lock b/packages/commitlint-wizardoc-e2e-tests/yarn.lock index f75519e..3aba67e 100644 --- a/packages/commitlint-wizardoc-e2e-tests/yarn.lock +++ b/packages/commitlint-wizardoc-e2e-tests/yarn.lock @@ -2,79 +2,165 @@ # yarn lockfile v1 -"@types/node@^15.3": - "integrity" "sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA==" - "resolved" "https://registry.npmjs.org/@types/node/-/node-15.6.1.tgz" - "version" "15.6.1" - -"ansi-styles@^4.1.0": - "integrity" "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==" - "resolved" "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz" - "version" "4.3.0" +"@types/glob@*": + version "7.1.3" + resolved "https://registry.npmjs.org/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183" + integrity sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w== dependencies: - "color-convert" "^2.0.1" + "@types/minimatch" "*" + "@types/node" "*" -"chalk@^4.1.1": - "integrity" "sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==" - "resolved" "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz" - "version" "4.1.1" +"@types/minimatch@*": + version "3.0.4" + resolved "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.4.tgz#f0ec25dbf2f0e4b18647313ac031134ca5b24b21" + integrity sha512-1z8k4wzFnNjVK/tlxvrWuK5WMt6mydWWP7+zvH5eFep4oj+UkrfiJTRtjCeBXNpwaA/FYqqtb4/QS4ianFpIRA== + +"@types/node@*": + version "15.6.1" + resolved "https://registry.npmjs.org/@types/node/-/node-15.6.1.tgz#32d43390d5c62c5b6ec486a9bc9c59544de39a08" + integrity sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA== + +"@types/shelljs@^0.8.8": + version "0.8.8" + resolved "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.8.tgz#e439c69929b88a2c8123c1a55e09eb708315addf" + integrity sha512-lD3LWdg6j8r0VRBFahJVaxoW0SIcswxKaFUrmKl33RJVeeoNYQAz4uqCJ5Z6v4oIBOsC5GozX+I5SorIKiTcQA== + dependencies: + "@types/glob" "*" + "@types/node" "*" + +balanced-match@^1.0.0: + version "1.0.2" + resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" + integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== + +brace-expansion@^1.1.7: + version "1.1.11" + resolved "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" + integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== + dependencies: + balanced-match "^1.0.0" + concat-map "0.0.1" + +commitlint-config-wizardoc@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/commitlint-config-wizardoc/-/commitlint-config-wizardoc-1.0.0.tgz#d8f4372b75667ee8b553f1b6fa6eed9553e42a93" + integrity sha512-ecOER5XBrTZVVIzRyXfGQMoe8C4OQevP4lYFK/HwB5jhFgCAX1TXiASYQLwgq4iU1hQcHMBc2inHVitVqRadHA== dependencies: - "ansi-styles" "^4.1.0" - "supports-color" "^7.1.0" + commitlint-plugin-wizardoc-rules "^1.0.0" -"color-convert@^2.0.1": - "integrity" "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==" - "resolved" "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz" - "version" "2.0.1" +commitlint-plugin-wizardoc-rules@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/commitlint-plugin-wizardoc-rules/-/commitlint-plugin-wizardoc-rules-1.0.0.tgz#3f6e8a42d42b31c7897a91bc224b85132768324b" + integrity sha512-V7NT3egc4LXBYeNtKnYYFtCAb8/3vlea9xNlky4r41HUHC9mx5w6mnKe7NQAucllkLGyYDL/FRt51UiyujrYPg== + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= + +function-bind@^1.1.1: + version "1.1.1" + resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" + integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== + +glob@^7.0.0: + version "7.1.7" + resolved "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90" + integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ== dependencies: - "color-name" "~1.1.4" - -"color-name@~1.1.4": - "integrity" "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - "resolved" "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz" - "version" "1.1.4" - -"has-flag@^4.0.0": - "integrity" "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" - "resolved" "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz" - "version" "4.0.0" - -"isexe@^2.0.0": - "integrity" "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" - "resolved" "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz" - "version" "2.0.0" - -"node-fetch@^2.6.1": - "integrity" "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" - "resolved" "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz" - "version" "2.6.1" - -"shq@^1.0.2": - "integrity" "sha512-8AvNyHL75DHlkbLmzF7nzTzT2F0qEfSewwxHjH79Ww8S+hGpIZVlf8b0TcdOwv4HqIkOVBInu9n+wqhUSl9Wag==" - "resolved" "https://registry.npmjs.org/shq/-/shq-1.0.2.tgz" - "version" "1.0.2" - -"supports-color@^7.1.0": - "integrity" "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==" - "resolved" "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz" - "version" "7.2.0" + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + +has@^1.0.3: + version "1.0.3" + resolved "https://registry.npmjs.org/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" + integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== dependencies: - "has-flag" "^4.0.0" + function-bind "^1.1.1" -"which@^2.0.2": - "integrity" "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==" - "resolved" "https://registry.npmjs.org/which/-/which-2.0.2.tgz" - "version" "2.0.2" +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= dependencies: - "isexe" "^2.0.0" + once "^1.3.0" + wrappy "1" + +inherits@2: + version "2.0.4" + resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +interpret@^1.0.0: + version "1.4.0" + resolved "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e" + integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA== -"zx@^1.12.0": - "integrity" "sha512-JvZxN3QTnZIUF5p9YVpqc/wm6Ghc5yVQd/p53KC0nnSK3RUfeuGMRrOnxJ5c4R4iYwY5F65i4e3BU59JD6svBw==" - "resolved" "https://registry.npmjs.org/zx/-/zx-1.12.0.tgz" - "version" "1.12.0" +is-core-module@^2.2.0: + version "2.4.0" + resolved "https://registry.npmjs.org/is-core-module/-/is-core-module-2.4.0.tgz#8e9fc8e15027b011418026e98f0e6f4d86305cc1" + integrity sha512-6A2fkfq1rfeQZjxrZJGerpLCTHRNEBiSgnu0+obeJpEPZRUooHgsizvzv0ZjJwOz3iWIHdJtVWJ/tmPr3D21/A== dependencies: - "@types/node" "^15.3" - "chalk" "^4.1.1" - "node-fetch" "^2.6.1" - "shq" "^1.0.2" - "which" "^2.0.2" + has "^1.0.3" + +minimatch@^3.0.4: + version "3.0.4" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" + integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== + dependencies: + brace-expansion "^1.1.7" + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= + dependencies: + wrappy "1" + +path-is-absolute@^1.0.0: + version "1.0.1" + resolved "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= + +path-parse@^1.0.6: + version "1.0.7" + resolved "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" + integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== + +rechoir@^0.6.2: + version "0.6.2" + resolved "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" + integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q= + dependencies: + resolve "^1.1.6" + +resolve@^1.1.6: + version "1.20.0" + resolved "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975" + integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A== + dependencies: + is-core-module "^2.2.0" + path-parse "^1.0.6" + +shelljs@^0.8.4: + version "0.8.4" + resolved "https://registry.npmjs.org/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2" + integrity sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ== + dependencies: + glob "^7.0.0" + interpret "^1.0.0" + rechoir "^0.6.2" + +wrappy@1: + version "1.0.2" + resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=