Skip to content
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
11 changes: 10 additions & 1 deletion @commitlint/ensure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@
"license": "MIT",
"devDependencies": {
"@commitlint/utils": "^20.0.0",
"@types/lodash.camelcase": "^4.3.8",
"@types/lodash.kebabcase": "^4.1.8",
"@types/lodash.snakecase": "^4.1.8",
"@types/lodash.startcase": "^4.4.8",
"@types/lodash.upperfirst": "^4.3.8",
"glob": "^11.0.0"
},
"dependencies": {
"@commitlint/types": "^20.4.0",
"kasi": "^2.0.1"
"lodash.camelcase": "^4.3.0",
"lodash.kebabcase": "^4.1.1",
"lodash.snakecase": "^4.1.1",
"lodash.startcase": "^4.4.0",
"lodash.upperfirst": "^4.3.1"
},
"gitHead": "e82f05a737626bb69979d14564f5ff601997f679"
}
4 changes: 2 additions & 2 deletions @commitlint/ensure/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from "node:path";
import { fileURLToPath } from "node:url";

import { globSync } from "glob";
import { toCamelCase } from "kasi";
import camelCase from "lodash.camelcase";

import * as ensure from "./index.js";

Expand All @@ -12,7 +12,7 @@ const __dirname = path.resolve(fileURLToPath(import.meta.url), "..");
test("exports all checkers", async () => {
const ignore = ["types"];
const expected = _glob("*.ts")
.map((f) => toCamelCase(f))
.map((f) => camelCase(f))
.sort()
.filter((item) => !ignore.includes(item));
const actual = Object.keys(ensure).sort();
Expand Down
24 changes: 11 additions & 13 deletions @commitlint/ensure/src/to-case.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
import { TargetCaseType } from "@commitlint/types";
import {
toCamelCase,
toKebabCase,
toSnakeCase,
toPascalCase,
toTitleCase,
} from "kasi";
import camelCase from "lodash.camelcase";
import kebabCase from "lodash.kebabcase";
import snakeCase from "lodash.snakecase";
import upperFirst from "lodash.upperfirst";
import startCase from "lodash.startcase";

export default function toCase(input: string, target: TargetCaseType): string {
switch (target) {
case "camel-case":
return toCamelCase(input);
return camelCase(input);
case "kebab-case":
return toKebabCase(input);
return kebabCase(input);
case "snake-case":
return toSnakeCase(input);
return snakeCase(input);
case "pascal-case":
return toPascalCase(input);
return upperFirst(camelCase(input));
case "start-case":
return toTitleCase(input);
return startCase(input);
case "upper-case":
case "uppercase":
return input.toUpperCase();
case "sentence-case":
case "sentencecase":
return `${input.charAt(0).toUpperCase()}${input.slice(1)}`;
return upperFirst(input);
case "lower-case":
case "lowercase":
case "lowerCase": // Backwards compat config-angular v4
Expand Down
78 changes: 78 additions & 0 deletions @commitlint/rules/src/subject-case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,81 @@ test('with numeric subject should succeed for "always uppercase"', async () => {
const expected = true;
expect(actual).toEqual(expected);
});

test("accepts lowercase Cyrillic subjects", async () => {
const message = "chore(deps): обновлены все зависимости";
const parsed = await parse(message);
const [actual] = subjectCase(parsed, "never", [
"sentence-case",
"start-case",
"pascal-case",
"upper-case",
]);

expect(actual).toBe(true);
});

test("rejects uppercase Cyrillic subjects", async () => {
const message = "chore(deps): ОБНОВЛЕНЫ ВСЕ ЗАВИСИМОСТИ";
const parsed = await parse(message);
const [actual] = subjectCase(parsed, "never", [
"sentence-case",
"start-case",
"pascal-case",
"upper-case",
]);

expect(actual).toBe(false);
});

test("accepts lowercase Chinese subjects", async () => {
const message = "fix(面试): 修复评价功能";
const parsed = await parse(message);
const [actual] = subjectCase(parsed, "never", [
"sentence-case",
"start-case",
"pascal-case",
"upper-case",
]);

expect(actual).toBe(true);
});

test("accepts lowercase Arabic subjects", async () => {
const message = "feat(مميزات): إضافة وظيفة جديدة";
const parsed = await parse(message);
const [actual] = subjectCase(parsed, "never", [
"sentence-case",
"start-case",
"pascal-case",
"upper-case",
]);

expect(actual).toBe(true);
});

test("accepts lowercase Hebrew subjects", async () => {
const message = "fix(תיקון): תיקון בעיה";
const parsed = await parse(message);
const [actual] = subjectCase(parsed, "never", [
"sentence-case",
"start-case",
"pascal-case",
"upper-case",
]);

expect(actual).toBe(true);
});

test("accepts mixed Latin and Cyrillic lowercase subjects", async () => {
const message = "chore(deps): update зависимости";
const parsed = await parse(message);
const [actual] = subjectCase(parsed, "never", [
"sentence-case",
"start-case",
"pascal-case",
"upper-case",
]);

expect(actual).toBe(true);
});
65 changes: 60 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1858,13 +1858,48 @@
resolved "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz#21413001973106cda1c3a9b91eedd4ccd5469d76"
integrity sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==

"@types/lodash.camelcase@^4.3.8":
version "4.3.9"
resolved "https://registry.npmjs.org/@types/lodash.camelcase/-/lodash.camelcase-4.3.9.tgz#da7b65013d6914fecb8759d5220a6ca9b658ee23"
integrity sha512-ys9/hGBfsKxzmFI8hckII40V0ASQ83UM2pxfQRghHAwekhH4/jWtjz/3/9YDy7ZpUd/H0k2STSqmPR28dnj7Zg==
dependencies:
"@types/lodash" "*"

"@types/lodash.kebabcase@^4.1.8":
version "4.1.9"
resolved "https://registry.npmjs.org/@types/lodash.kebabcase/-/lodash.kebabcase-4.1.9.tgz#48d3df753b89499e75eba5e017979b560d69df85"
integrity sha512-kPrrmcVOhSsjAVRovN0lRfrbuidfg0wYsrQa5IYuoQO1fpHHGSme66oyiYA/5eQPVl8Z95OA3HG0+d2SvYC85w==
dependencies:
"@types/lodash" "*"

"@types/lodash.mergewith@^4.6.8":
version "4.6.9"
resolved "https://registry.npmjs.org/@types/lodash.mergewith/-/lodash.mergewith-4.6.9.tgz#7093028a36de3cae4495d03b9d92c351cab1f8bf"
integrity sha512-fgkoCAOF47K7sxrQ7Mlud2TH023itugZs2bUg8h/KzT+BnZNrR2jAOmaokbLunHNnobXVWOezAeNn/lZqwxkcw==
dependencies:
"@types/lodash" "*"

"@types/lodash.snakecase@^4.1.8":
version "4.1.9"
resolved "https://registry.npmjs.org/@types/lodash.snakecase/-/lodash.snakecase-4.1.9.tgz#2d2b3313a44500cb6d8a1c598e0353778d4420d2"
integrity sha512-emBZJUiNlo+QPXr1junMKXwzHJK9zbFvTVdyAoorFcm1YRsbzkZCYPTVMM9AW+dlnA6utG7vpfvOs8alxv/TMw==
dependencies:
"@types/lodash" "*"

"@types/lodash.startcase@^4.4.8":
version "4.4.9"
resolved "https://registry.npmjs.org/@types/lodash.startcase/-/lodash.startcase-4.4.9.tgz#fba0daa4bb5f279e05628c03193ae1d5e32c438d"
integrity sha512-C0M4DlN1pnn2vEEhLHkTHxiRZ+3GlTegpoAEHHGXnuJkSOXyJMHGiSc+SLRzBlFZWHsBkixe6FqvEAEU04g14g==
dependencies:
"@types/lodash" "*"

"@types/lodash.upperfirst@^4.3.8":
version "4.3.9"
resolved "https://registry.npmjs.org/@types/lodash.upperfirst/-/lodash.upperfirst-4.3.9.tgz#66e150885a67866ed8bc4331c8c305ab682a198c"
integrity sha512-bYhT1QEsk9/ggrFjK86Pb5bnKJgTBbpVA77Ygbb1aW1oiWJNGRbVjSlQ9We/ihB9vVpX5WqDJvbISXlukGR+dQ==
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.17.16"
resolved "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.16.tgz#94ae78fab4a38d73086e962d0b65c30d816bfb0a"
Expand Down Expand Up @@ -5155,11 +5190,6 @@ just-diff@^6.0.0:
resolved "https://registry.npmjs.org/just-diff/-/just-diff-6.0.2.tgz#03b65908543ac0521caf6d8eb85035f7d27ea285"
integrity sha512-S59eriX5u3/QhMNq3v/gm8Kd0w8OS6Tz2FS1NG4blv+z0MuQcBRJyFWjdovM0Rad4/P4aUPFtnkNjMjyMlMSYA==

kasi@^2.0.1:
version "2.0.1"
resolved "https://registry.npmjs.org/kasi/-/kasi-2.0.1.tgz#878e91d06816990bb935fdc8341116a95ef72edd"
integrity sha512-8qhiHZ1BN26ig1+jQ9fWEk6dj8T1wuxs00QRJfXIANI4scto1EuPUgqj+mxHls52WBfdTNJGQ8yYw9rDpWUcgQ==

keyv@^4.5.4:
version "4.5.4"
resolved "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz#a879a99e29452f942439f2a405e3af8b31d4de93"
Expand Down Expand Up @@ -5364,6 +5394,11 @@ locate-path@^6.0.0:
dependencies:
p-locate "^5.0.0"

lodash.camelcase@^4.3.0:
version "4.3.0"
resolved "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
integrity sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==

lodash.clonedeep@^4.5.0:
version "4.5.0"
resolved "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
Expand All @@ -5374,6 +5409,11 @@ lodash.ismatch@^4.4.0:
resolved "https://registry.npmjs.org/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
integrity sha512-fPMfXjGQEV9Xsq/8MTSgUf255gawYRbjwMyDbcvDhXgV7enSZA0hynz6vMPnpAb5iONEzBHBPsT+0zes5Z301g==

lodash.kebabcase@^4.1.1:
version "4.1.1"
resolved "https://registry.npmjs.org/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36"
integrity sha512-N8XRTIMMqqDgSy4VLKPnJ/+hpGZN+PHQiJnSenYqPaVV/NCqEogTnAdZLQiGKhxX+JCs8waWq2t1XHWKOmlY8g==

lodash.map@^4.5.1:
version "4.6.0"
resolved "https://registry.npmjs.org/lodash.map/-/lodash.map-4.6.0.tgz#771ec7839e3473d9c4cde28b19394c3562f4f6d3"
Expand All @@ -5389,6 +5429,21 @@ lodash.mergewith@^4.6.2:
resolved "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz#617121f89ac55f59047c7aec1ccd6654c6590f55"
integrity sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==

lodash.snakecase@^4.1.1:
version "4.1.1"
resolved "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz#39d714a35357147837aefd64b5dcbb16becd8f8d"
integrity sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==

lodash.startcase@^4.4.0:
version "4.4.0"
resolved "https://registry.npmjs.org/lodash.startcase/-/lodash.startcase-4.4.0.tgz#9436e34ed26093ed7ffae1936144350915d9add8"
integrity sha512-+WKqsK294HMSc2jEbNgpHpd0JfIBhp7rEV4aqXWqFr6AlXov+SlcgB1Fv01y2kGe3Gc8nMW7VA0SrGuSkRfIEg==

lodash.upperfirst@^4.3.1:
version "4.3.1"
resolved "https://registry.npmjs.org/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz#1365edf431480481ef0d1c68957a5ed99d49f7ce"
integrity sha512-sReKOYJIJf74dhJONhU4e0/shzi1trVbSWDOhKYE5XV2O+H7Sb2Dihwuc7xWxVl+DgFPyTqIN3zMfT9cq5iWDg==

[email protected], lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
Expand Down