From d0edf3ca34b9374650c28fb7a557c9fd2c3d8007 Mon Sep 17 00:00:00 2001 From: vince Date: Mon, 8 Jul 2024 22:41:08 +0800 Subject: [PATCH] fix(@vben/commitlint-config): scope is not suitable for scoped package names --- .../commitlint-config/package.json | 1 + .../commitlint-config/src/index.ts | 31 ++++++++++++------- pnpm-lock.yaml | 14 +++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/internal/lint-configs/commitlint-config/package.json b/internal/lint-configs/commitlint-config/package.json index 557c3e37..a6716adc 100644 --- a/internal/lint-configs/commitlint-config/package.json +++ b/internal/lint-configs/commitlint-config/package.json @@ -31,6 +31,7 @@ "@commitlint/cli": "^19.3.0", "@commitlint/config-conventional": "^19.2.2", "@vben/node-utils": "workspace:*", + "commitlint-plugin-function-rules": "^4.0.0", "cz-git": "^1.9.3", "czg": "^1.9.3" } diff --git a/internal/lint-configs/commitlint-config/src/index.ts b/internal/lint-configs/commitlint-config/src/index.ts index b49b01a4..95ead304 100644 --- a/internal/lint-configs/commitlint-config/src/index.ts +++ b/internal/lint-configs/commitlint-config/src/index.ts @@ -6,12 +6,8 @@ import { getPackagesSync } from '@vben/node-utils'; const { packages } = getPackagesSync(); -const pkgs = packages.map((pkg) => { - return pkg.packageJson.name?.replace('@vben-core/', ''); -}); - -const scopes = [ - ...pkgs, +const allowedScopes = [ + ...packages.map((pkg) => pkg.packageJson.name), 'project', 'style', 'lint', @@ -33,6 +29,7 @@ const scopeComplete = execSync('git status --porcelain || true') const userConfig: UserConfig = { extends: ['@commitlint/config-conventional'], + plugins: ['commitlint-plugin-function-rules'], prompt: { /** @use `pnpm commit :f` */ alias: { @@ -102,16 +99,28 @@ const userConfig: UserConfig = { * ^^^^^^^^^^^^^^ */ 'footer-leading-blank': [1, 'always'], + /** + * type[scope]: [function] description + * ^^^^^ + */ + 'function-rules/scope-enum': [ + 2, // level: error + 'always', + (parsed: { scope: string }) => { + if (!parsed.scope || allowedScopes.includes(parsed.scope)) { + return [true]; + } + + return [false, `scope must be one of ${allowedScopes.join(', ')}`]; + }, + ], /** * type[scope]: [function] description [No more than 108 characters] * ^^^^^ */ 'header-max-length': [2, 'always', 108], - /** - * type[scope]: [function] description - * ^^^^^ - */ - 'scope-enum': [2, 'always', scopes], + + 'scope-enum': [0], 'subject-case': [0], 'subject-empty': [2, 'never'], 'type-empty': [2, 'never'], diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4c978988..b07ef11d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -255,6 +255,9 @@ importers: '@vben/node-utils': specifier: workspace:* version: link:../../node-utils + commitlint-plugin-function-rules: + specifier: ^4.0.0 + version: 4.0.0(@commitlint/lint@19.2.2) cz-git: specifier: ^1.9.3 version: 1.9.3 @@ -3221,6 +3224,7 @@ packages: '@ls-lint/ls-lint@2.2.3': resolution: {integrity: sha512-ekM12jNm/7O2I/hsRv9HvYkRdfrHpiV1epVuI2NP+eTIcEgdIdKkKCs9KgQydu/8R5YXTov9aHdOgplmCHLupw==} + cpu: [x64, arm64, s390x] os: [darwin, linux, win32] hasBin: true @@ -4682,6 +4686,12 @@ packages: resolution: {integrity: sha512-buhp5kePrmda3vhc5B9t7pUQXAb2Tnd0qgpkIhPhkHXxJpiPJ11H0ZEU0oBpJ2QztSbzG/ZxMj/CHsYJqRHmyg==} engines: {node: '>= 12.0.0'} + commitlint-plugin-function-rules@4.0.0: + resolution: {integrity: sha512-ddZAgEm4MtgwHiPCb/mFpPeN2mW/doN7l14Lt9g2nFV3NpZVL0RJ6hFU/JJuEqRTVBlji/qmGzMeNR8qZ9BXfw==} + engines: {node: '>=20'} + peerDependencies: + '@commitlint/lint': '>=19 <20' + common-tags@1.8.2: resolution: {integrity: sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA==} engines: {node: '>=4.0.0'} @@ -13689,6 +13699,10 @@ snapshots: comment-parser@1.4.1: {} + commitlint-plugin-function-rules@4.0.0(@commitlint/lint@19.2.2): + dependencies: + '@commitlint/lint': 19.2.2 + common-tags@1.8.2: {} commondir@1.0.1: {}