Community编程与开发github.com

Commitlint 提交信息校验

为项目配置提交信息验证。当项目包含 `commitlint.config.js` 或 `.commitlintrc` 文件时使用。用于配置 CI/CD 以强制校验提交格式。提取提交规则用于 LLM 提示生成。调试提交信息被拒绝的错误。

Commitlint 提交信息校验 是什么?

此技能详细介绍如何使用 commitlint 来验证提交信息是否符合 Conventional Commits 格式。它提供了一套完整的指南,涵盖配置检测、规则设置、常用配置、CLI 使用、规则参考以及编程式使用方法。该技能特别适用于在 CI/CD 管道或预提交 hooks 中集成提交信息验证,从而确保项目提交历史的一致性和规范性。它还展示了如何从 commitlint 配置中提取规则,用于生成 LLM 提示,以生成更高质量的提交信息。支持的平台包括 Node.js 项目,通过 npm、yarn 或 pnpm 安装。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Jamie-BitFlight/claude_skills/tree/main/plugins/commitlint/skills/commitlint

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Commitlint

使用 commitlint 配置和规则,根据 Conventional Commits 格式验证提交信息。

何时使用此技能

在以下场景使用此技能:

  • 为仓库设置 commitlint
  • 配置 commitlint 规则和可共享配置
  • 将 commitlint 集成到预提交 hooks 或 CI/CD 管道中
  • 从 commitlint 配置中提取规则,为提交信息生成生成 LLM 提示
  • 以编程方式验证提交信息
  • 排查 commitlint 配置或验证错误
  • 理解 commitlint 规则语法和严重级别
  • 检测仓库中的 commitlint 配置文件

核心功能

配置检测

Commitlint 使用 cosmiconfig 按以下优先级查找配置文件:

专用配置文件:

.commitlintrc
.commitlintrc.json
.commitlintrc.yaml
.commitlintrc.yml
.commitlintrc.js
.commitlintrc.cjs
.commitlintrc.mjs
.commitlintrc.ts
.commitlintrc.cts
commitlint.config.js
commitlint.config.cjs
commitlint.config.mjs
commitlint.config.ts
commitlint.config.cts

包文件:

  • package.json 中的 commitlint 字段
  • package.yaml (PNPM) 中的 commitlint 字段

配置格式

JavaScript ES Modules(推荐):

// commitlint.config.js 或 commitlint.config.mjs
export default {
  extends: ['@commitlint/config-conventional'],
};

TypeScript:

// commitlint.config.ts
import type { UserConfig } from '@commitlint/types';
import { RuleConfigSeverity } from '@commitlint/types';

const config: UserConfig = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [RuleConfigSeverity.Error, 'always', ['feat', 'fix', 'docs']],
  },
};

export default config;

JSON:

{
  "extends": ["@commitlint/config-conventional"]
}

YAML:

extends:
  - "@commitlint/config-conventional"

规则配置

规则配置为数组:[级别, 适用性, 值]

严重级别:

级别含义TypeScript 枚举
0禁用RuleConfigSeverity.Disabled
1警告RuleConfigSeverity.Warning
2错误RuleConfigSeverity.Error

适用性:

  • 'always' - 规则必须匹配
  • 'never' - 规则不得匹配

示例规则:

rules: {
  // 如果 type 不在枚举中,则报错
  'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert']],

  // 如果 type 为空,则报错
  'type-empty': [2, 'never'],

  // 如果 subject 为空,则报错
  'subject-empty': [2, 'never'],

  // 如果 header 超过 100 字符,则报错
  'header-max-length': [2, 'always', 100],

  // 如果 subject 以句点结尾,则报错
  'subject-full-stop': [2, 'never', '.'],

  // 如果 body 没有前导空行,则警告
  'body-leading-blank': [1, 'always'],
}

常用配置

@commitlint/config-conventional

最广泛使用的可共享配置。默认错误级别的规则:

规则配置通过示例失败示例
type-enum['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test']fix: messagefoo: message
type-case'lowerCase'fix: messageFIX: message
type-emptyneverfix: message: message
subject-casenever + ['sentence-case', 'start-case', 'pascal-case', 'upper-case']fix: some messagefix: Some Message
subject-emptyneverfix: messagefix:
subject-full-stopnever, '.'fix: messagefix: message.
header-max-length100短 headerHeader > 100 字符
body-leading-blankalways (警告)body 前有空行无空行
body-max-line-length100行 <= 100 字符行 > 100 字符
footer-leading-blankalways (警告)footer 前有空行无空行
footer-max-line-length100行 <= 100 字符行 > 100 字符

完整配置模式

// commitlint.config.js
export default {
  // 扩展可共享配置(通过 node 解析)
  extends: ['@commitlint/config-conventional'],

  // 解析提交信息的解析器预设
  parserPreset: 'conventional-changelog-atom',

  // 输出格式化程序
  formatter: '@commitlint/format',

  // 自定义规则(覆盖继承的规则)
  rules: {
    'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore']],
  },

  // 返回 true 以忽略特定提交的函数
  // 与默认忽略模式合并(合并提交、撤销、语义版本标签)
  ignores: [(commit) => commit.includes('WIP')],

  // 是否使用默认忽略模式
  // 默认模式:'Merge pull request'、'Revert X'、'v1.2.3' 等
  defaultIgnores: true,

  // 失败时显示的自定义帮助 URL
  helpUrl: 'https://example.com/commit-guidelines',

  // 提示配置(用于 @commitlint/cz-commitlint)
  prompt: {
    messages: {},
    questions: {
      type: {
        description: '选择更改类型:',
      },
    },
  },
};

CLI 使用

安装

# npm
npm install -D @commitlint/cli @commitlint/config-conventional

# yarn
yarn add -D @commitlint/cli @commitlint/config-conventional

# pnpm
pnpm add -D @commitlint/cli @commitlint/config-conventional

常用命令

# 检查上次提交
npx commitlint --last

# 检查一系列提交
npx commitlint --from HEAD~5

# 从特定提交开始检查
npx commitlint --from abc1234

# 从标准输入检查信息
echo "feat: add feature" | npx commitlint

# 从文件检查信息
npx commitlint < .git/COMMIT_EDITMSG

# 使用编辑标志检查(读取 .git/COMMIT_EDITMSG)
npx commitlint --edit

# 使用自定义配置路径检查
npx commitlint --config ./custom-commitlint.config.js

# 打印解析后的配置
npx commitlint --print-config

# 严格模式(警告变为退出码 2)
npx commitlint --last --strict

退出码

代码含义
0成功(无错误)
1发现 lint 错误
2发现警告(仅限严格模式)
3发现错误(严格模式)
9配置文件缺失(使用 -g 标志时)

规则参考

Type 规则

规则条件默认适用性
type-enumtype 存在于值中always
type-casetype 的格式为 值always, 'lower-case'
type-emptytype 为空never
type-max-lengthtype 的字符数不超过 值always, Infinity
type-min-lengthtype 的字符数不少于 值always, 0

Subject 规则

规则条件默认适用性
subject-casesubject 的格式为 值always
subject-emptysubject 为空never
subject-full-stopsubject 以 值 结尾never, '.'
subject-max-lengthsubject 的字符数不超过 值always, Infinity
subject-min-lengthsubject 的字符数不少于 值always, 0
subject-exclamation-marksubject 在 : 前有感叹号never

Scope 规则

规则条件默认适用性
scope-enumscope 存在于值中always, []
scope-casescope 的格式为 值always, 'lower-case'
scope-emptyscope 为空never
scope-max-lengthscope 的字符数不超过 值always, Infinity
scope-min-lengthscope 的字符数不少于 值always, 0

Header 规则

规则条件默认适用性
header-caseheader 的格式为 值always, 'lower-case'
header-full-stopheader 以 值 结尾never, '.'
header-max-lengthheader 的字符数不超过 值always, 72
header-min-lengthheader 的字符数不少于 值always, 0
header-trimheader 没有前导或尾随空格always

Body 规则

规则条件默认适用性
body-leading-blankbody 以空行开头always
body-emptybody 为空never
body-max-lengthbody 的字符数不超过 值always, Infinity
body-max-line-lengthbody 行的字符数不超过 值(URL 除外)always, Infinity
body-min-lengthbody 的字符数不少于 值always, 0
body-casebody 的格式为 值always, 'lower-case'
body-full-stopbody 以 值 结尾never, '.'

Footer 规则

规则条件默认适用性
footer-leading-blankfooter 以空行开头always
footer-emptyfooter 为空never
footer-max-lengthfooter 的字符数不超过 值always, Infinity
footer-max-line-lengthfooter 行的字符数不超过 值always, Infinity
footer-min-lengthfooter 的字符数不少于 值always, 0

格式值

对于检查格式的规则(*-case):

[
  'lower-case',    // 小写
  'upper-case',    // 大写
  'camel-case',    // 驼峰式
  'kebab-case',    // 短横线式
  'pascal-case',   // 帕斯卡式
  'sentence-case', // 句子式
  'snake-case',    // 下划线式
  'start-case',    // 起始大写式
]

编程式使用

加载配置

import load from '@commitlint/load';

async function getCommitlintConfig() {
  const config = await load();
  console.log(config.rules);
  return config;
}

验证信息

import load from '@commitlint/load';
import lint from '@commitlint/lint';

async function validateMessage(message) {
  const config = await load();
  const result = await lint(message, config.rules);

  return {
    valid: result.valid,
    errors: result.errors,
    warnings: result.warnings,
  };
}

LLM 集成模式

提取规则用于提示生成

从 commitlint 配置生成 LLM 友好的约束:

def extract_rules_for_prompt(config: dict) -> str:
    """从 commitlint 配置中提取规则,转换为 LLM 友好的格式。"""
    rules = config.get("rules", {})
    prompt_parts = []

    # 如果存在 type-enum,则提取
    if "type-enum" in rules:
        level, applicability, types = rules["type-enum"]
        if level > 0 and applicability == "always":
            prompt_parts.append(f"允许的提交类型:{', '.join(types)}")

    # 如果存在 scope-enum,则提取
    if "scope-enum" in rules:
        level, applicability, scopes = rules["scope-enum"]
        if level > 0 and applicability == "always":
            prompt_parts.append(f"允许的 scope:{', '.join(scopes)}")

    # 提取 header 长度限制
    if "header-max-length" in rules:
        level, applicability, max_length = rules["header-max-length"]
        if level > 0:
            prompt_parts.append(f"header 最多 {max_length} 个字符")

    return "\n".join(prompt_parts)

# 用法示例
config = load()
prompt_rules = extract_rules_for_prompt(config)
print(prompt_rules)

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

Jamie-BitFlight/agentskill-kaizen-meta-docs

Agentskill kaizen plugin documentation index. Load when needing to read about cross-platform notes, improvement plans, or DuckDB integration.

Jamie-BitFlight/bash-51-features

Bash 5.1 release features and improvements with practical examples. Use when working with Bash 5.1 features, epoch time variables, redirection enhancements, or when user asks about Bash 5.1 changes, new features, or version-specific capabilities.

Jamie-BitFlight/bash-52-features

Bash 5.2 release features and improvements with practical examples. Use when working with Bash 5.2 features, variable handling enhancements, readline improvements, or when user asks about Bash 5.2 changes, new features, or version-specific capabilities.

Jamie-BitFlight/bash-53-features

Bash 5.3 release features and improvements with practical examples. Use when working with Bash 5.3 features, new command substitution, GLOBSORT, loadable builtins, or when user asks about Bash 5.3 changes, new features, or version-specific capabilities.

Jamie-BitFlight/bash-development

This skill should be used when the user asks to "write a bash script", "create a shell script", "implement bash function", "parse arguments in bash", "handle errors in bash", or mentions bash development, shell scripting, script templates, or modern bash patterns.

Jamie-BitFlight/bash-lint

This skill should be used when the user asks to "lint bash script", "run shellcheck", "format shell script", "use shfmt", "fix shellcheck errors", or mentions shell script linting, formatting, code quality, or pre-commit hooks for bash.

Jamie-BitFlight/bash-logging

This skill should be used when the user asks to "add logging to bash script", "colorize output", "implement log levels", "CI/CD sections", "terminal colors in bash", or mentions logging functions, emoji output, collapsible CI sections, or shlocksmith.

Jamie-BitFlight/bash-portability

This skill should be used when the user asks about "POSIX compatibility", "portable shell scripts", "cross-shell compatibility", "bashisms", "shebang selection", or mentions writing scripts that work on different shells (bash, sh, dash, zsh) or different systems.

Jamie-BitFlight/bash-testing

This skill should be used when the user asks to "test bash script", "write shell tests", "use shunit2", "use shellspec", "create test suite for bash", or mentions unit testing, test frameworks, mocking, or test-driven development for shell scripts.

Jamie-BitFlight/brainstorming-skill

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or when users request help with ideation, marketing, and strategic planning. Explores user intent, requirements, and design before implementation using research-validated prompt patterns.

Jamie-BitFlight/clang-format

Configure clang-format code formatting. Use when: user mentions clang-format or .clang-format, analyzing code style/patterns, creating/modifying formatting config, troubleshooting formatting, brace styles/indentation/spacing/alignment/pointer alignment, or codifying conventions.

Jamie-BitFlight/conventional-commits

When writing a git commit message. When task completes and changes need committing. When project uses semantic-release, commitizen, git-cliff. When choosing between feat/fix/chore/docs types. When indicating breaking changes. When generating changelogs from commit history.

Jamie-BitFlight/dasel-reference

Use when querying, modifying, or converting JSON, YAML, TOML, XML, CSV, HCL, or INI with dasel v3. Complete reference for selectors, functions, conditionals, variables, spread operator, type casting, and format-specific patterns.

Jamie-BitFlight/data-exploration

Use when exploring unknown structured data files with dasel v3 — discover schema, list keys, find nested values, sample arrays, identify data types across JSON, YAML, TOML, XML, CSV, HCL, INI formats

Jamie-BitFlight/data-transformation

Use when modifying, converting, or transforming structured data with dasel v3 — in-place mutations, format conversion, batch operations, array manipulation, object construction, and merge patterns across JSON, YAML, TOML, XML, CSV, HCL, INI

Jamie-BitFlight/delegate

Decompose substantive work into phases, dispatch each phase to a sub-agent, and adjudicate what comes back. Use whenever a request asks for implementation, investigation, a fix, a review, or any change to files — including small ones — and whenever you are about to read source or run a diagnostic yourself instead of handing it off. Also use when a report from a sub-agent needs judging, when a phase needs re-dispatching, or when a user names one instance of a pattern. Does not apply when your own prompt begins "Your ROLE_TYPE is sub-agent." — then follow references/sub-agent-contract.md instead.

Jamie-BitFlight/enterprise-hibernate-hbm

Dasel v3 query patterns for Hibernate .hbm.xml mapping files — entity-table binding, Java property-to-column extraction, one-to-many set/list/bag relationship tracing, many-to-one foreign key discovery, batch scanning across 60+ HBM files. Use when querying Hibernate ORM class mappings, extracting schema metadata from Java persistence layer, or auditing entity-column relationships in enterprise legacy codebases.

Jamie-BitFlight/enterprise-installanywhere

Dasel v3 query patterns for InstallAnywhere .iap_xml installer definitions — use when querying action sequences, discovering variables, resolving platform conditions, navigating panels, or comparing installer variants. Files are 2.5+ MB, 65,000+ lines — too large for context reads, requires structural dasel queries.

Jamie-BitFlight/enterprise-maven-pom

Dasel v3 selector patterns for Maven POM XML files — use when querying dependency versions, filtering by groupId or scope, extracting module hierarchy from parent POMs, or detecting version conflicts across enterprise multi-module Java projects. Load this skill when working with pom.xml files using dasel.

Jamie-BitFlight/enterprise-spring-xml

Dasel v3 selectors for Spring bean factory XML — use when querying any Spring ApplicationContext XML for bean discovery, dependency wiring, JMS destination mapping, property injection extraction, or cross-bean reference tracing. Load this skill before writing dasel selectors against Spring bean XML files (applicationContext.xml, *_beans.xml, spring-*.xml).

相关技能