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.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 new file mode 100644 index 0000000..9b5556b --- /dev/null +++ b/packages/commitlint-plugin-wizardoc-rules/src/constants.ts @@ -0,0 +1 @@ +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.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/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/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/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" 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"