SuperAPI AI 工具集

commitlint

部署与运维

查看项目

更新于 10-16 06:19

技能介绍

用途:为项目配置并运行 commitlint,按 Conventional Commits 格式校验提交信息,可用于仓库配置、规则与共享配置设定、pre-commit 钩子或 CI/CD 流水线集成、程序化校验、排查配置或校验错误,以及从 commitlint 配置提取规则以生成 LLM 提交信息提示词。

主要能力:通过 cosmiconfig 检测配置,优先级为专用配置文件(如 .commitlintrc、.commitlintrc.json、.commitlintrc.js、commitlint.config.js、commitlint.config.ts 等)再到 package.json 或 package.yaml(PNPM)中的 commitlint 字段。配置格式支持 JS/CJS/MJS/TS、JSON、YAML,且可 extends 共享配置。规则数组格式为 [level, applicability, value],level 0/1/2 对应禁用、警告、错误,applicability 为 'always' 或 'never'。常用共享配置 @commitlint/config-conventional 提供 type-enum、type-case、type-empty、subject-case、subject-empty、subject-full-stop、header-max-length、body/footer 相关规则。CLI 支持 --last、--from、--edit、--config、--print-config、--strict,退出码 0 成功、1 有错误、2 警告、3 错误、9 配置缺失。提供 @commitlint/load 与 @commitlint/lint 用于程序化加载配置和校验。

用法:安装 npm install -D @commitlint/cli @commitlint/config-conventional(或 yarn/pnpm 等价命令);常用命令如 npx commitlint --last、npx commitlint --from HEAD~5、echo "feat: add feature" | npx commitlint、npx commitlint --edit;首次配置可 extends 共享配置。

限制:配置必须至少包含 extends 或 rules,否则报错;scope-enum 为空数组会放行所有 scope;@commitlint/config-conventional 的 subject-case 采用 never 列表,表示禁止而非要求这些大小写;Node v24 使用 ESM 需 .mjs 或 package.json 加 "type": "module"。pre-commit 钩子集成需由钩子管理器配置。其余细节暂未提供。