Skip to content

[WIP] add breakChangeSymbol rule #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions packages/commitlint-config-wizardoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
"devDependencies": {
"@commitlint/types": "^12.1.4"
},
"dependencies": {}
}
"dependencies": {
"commitlint-plugin-wizardoc-rules": "^1.0.0"
}
}
8 changes: 4 additions & 4 deletions packages/commitlint-config-wizardoc/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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"],
Expand Down
6 changes: 5 additions & 1 deletion packages/commitlint-config-wizardoc/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ export enum LexicalElement {
TYPE = "type",
SCOPE = "scope",
TICKET = "ticket",
SYMBOL = "symbol",
}

export enum CommitType {
FEAT = "Feat",
INIT = "Init",
REMOVE = "Remove",
DELETE = "Delete",
UPDATE = "Update",
REFACTOR = "Refactor",
MOVE = "Move",
NEW = "New",
ADD = "Add",
PATCH = "Patch",
FIX = "Fix",
TEST = "Test",
STUB = "Stub",
CHORE = "Chore",
}

export const CONVERSION_MATCH_REGEX = /^\[(\w+?)(?:\:\:(\w*))?\]\s(.*)$/;
export const CONVERSION_MATCH_REGEX = /^(.?)\[(\w+?)(?:\:\:(\w*))?\]\s(.*)$/;
2 changes: 1 addition & 1 deletion packages/commitlint-plugin-wizardoc-rules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "commitlint-plugin-wizardoc-rules",
"version": "1.0.0",
"main": "index.js",
"main": "./dist/index.js",
"license": "MIT"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { BREAK_CHANGE_SYMBOL } from "./constants";
import { Commit, Rule, RuleOutcome } from "@commitlint/types";

export type WithSymbol<T> = T & {
symbol: string;
};

export type CommitWithSymbol = WithSymbol<Commit>;

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`,
];
};
1 change: 1 addition & 0 deletions packages/commitlint-plugin-wizardoc-rules/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const BREAK_CHANGE_SYMBOL = "!";
13 changes: 12 additions & 1 deletion packages/commitlint-plugin-wizardoc-rules/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
export {};
import { breakChangeSymbolRule } from "./break-change-symbol-rule";
import { Plugin } from "@commitlint/types";

export const plugins: Record<string, Plugin[]> = {
plugins: [
{
rules: {
"break-change-prefix": breakChangeSymbolRule,
},
},
],
};
Original file line number Diff line number Diff line change
@@ -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<Commit>;

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);
});
});

This file was deleted.

4 changes: 4 additions & 0 deletions packages/commitlint-plugin-wizardoc-rules/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"extends": "../../tsconfig.base",
"include": ["src"],
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
},
"exclude": ["node_modules"]
}
114 changes: 57 additions & 57 deletions packages/commitlint-wizardoc-e2e-tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down