Bläddra i källkod

fix(@vben/commitlint-config): scope is not suitable for scoped package names

vince 8 månader sedan
förälder
incheckning
d0edf3ca34

+ 1 - 0
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"
   }

+ 19 - 10
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: {
@@ -103,15 +100,27 @@ const userConfig: UserConfig = {
      */
     'footer-leading-blank': [1, 'always'],
     /**
-     * type[scope]: [function] description [No more than 108 characters]
+     * type[scope]: [function] description
      *      ^^^^^
      */
-    'header-max-length': [2, 'always', 108],
+    '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
+     * type[scope]: [function] description [No more than 108 characters]
      *      ^^^^^
      */
-    'scope-enum': [2, 'always', scopes],
+    'header-max-length': [2, 'always', 108],
+
+    'scope-enum': [0],
     'subject-case': [0],
     'subject-empty': [2, 'never'],
     'type-empty': [2, 'never'],

+ 14 - 0
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: {}