Community程式設計與開發github.com

Commitlint

在設置專案提交訊息驗證時使用。當專案包含 commitlint.config.js 或 .commitlintrc 檔案時使用。配置 CI/CD 以強制執行提交格式時使用。為 LLM 提示詞提取提交規則時使用。除錯提交訊息拒絕錯誤時使用。

Commitlint 是什麼?

Commitlint 是一個專門用來驗證 Git 提交訊息是否符合 Conventional Commits 規範的技能。它透過讀取專案中的 commitlint 設定檔(例如 commitlint.config.js 或 .commitlintrc),定義一組嚴格的規則來檢查提交訊息的格式、類型、範圍、主旨、內文與結尾等部分。支援多種設定格式(JavaScript、TypeScript、JSON、YAML)與 npm/yarn/pnpm 套件管理器,並可整合至 pre-commit hooks 或 CI/CD 管線,實現自動化提交規範。此外,此技能還能從現有設定中提取規則,方便為 LLM 生成提交訊息提供明確的約束條件,從而提高 AI 輔助開發的準確性。無論是設定新規則、除錯驗證失敗,還是為團隊制定統一的提交慣例,Commitlint 都能提供結構化且可自訂的解決方案。

相容平台~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 整合到 pre-commit 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"

規則設定

規則以陣列形式配置:[level, applicability, value]

嚴重性層級:

層級意義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短標題標題 > 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 以忽略特定提交的函式
  // 與預設忽略模式合併(合併提交、還原提交、semver 標籤)
  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 存在於 value 中always
type-casetype 符合 case value 格式always, 'lower-case'
type-emptytype 為空never
type-max-lengthtype 長度小於等於 valuealways, Infinity
type-min-lengthtype 長度大於等於 valuealways, 0

主旨(Subject)規則

規則條件預設適用性
subject-casesubject 符合 case value 格式always
subject-emptysubject 為空never
subject-full-stopsubject 以 value 結尾never, '.'
subject-max-lengthsubject 長度小於等於 valuealways, Infinity
subject-min-lengthsubject 長度大於等於 valuealways, 0
subject-exclamation-marksubject 在 : 之前有驚嘆號never

範圍(Scope)規則

規則條件預設適用性
scope-enumscope 存在於 value 中always, []
scope-casescope 符合 case value 格式always, 'lower-case'
scope-emptyscope 為空never
scope-max-lengthscope 長度小於等於 valuealways, Infinity
scope-min-lengthscope 長度大於等於 valuealways, 0

標題(Header)規則

規則條件預設適用性
header-caseheader 符合 case value 格式always, 'lower-case'
header-full-stopheader 以 value 結尾never, '.'
header-max-lengthheader 長度小於等於 valuealways, 72
header-min-lengthheader 長度大於等於 valuealways, 0
header-trimheader 前後無空白字元always

內文(Body)規則

規則條件預設適用性
body-leading-blankbody 以空白行開頭always
body-emptybody 為空never
body-max-lengthbody 長度小於等於 valuealways, Infinity
body-max-line-lengthbody 的行長度小於等於 value(URL 除外)always, Infinity
body-min-lengthbody 長度大於等於 valuealways, 0
body-casebody 符合 case value 格式always, 'lower-case'
body-full-stopbody 以 value 結尾never, '.'

結尾(Footer)規則

規則條件預設適用性
footer-leading-blankfooter 以空白行開頭always
footer-emptyfooter 為空never
footer-max-lengthfooter 長度小於等於 valuealways, Infinity
footer-max-line-lengthfooter 的行長度小於等於 valuealways, Infinity
footer-min-lengthfooter 長度大於等於 valuealways, 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"允許的範圍:{', '.join(scopes)}")

    # 提取 subject-case(若存在)
    if "subject-case" in rules:
        level, _, case = rules["subject-case"]
        if level > 0:
            prompt_parts.append(f"主旨格式:{case}")

    # 提取 header-max-length(若存在)
    if "header-max-length" in rules:
        level, _, max_len = rules["header-max-length"]
        if level > 0:
            prompt_parts.append(f"標題最大長度:{max_len} 個字元")

    return "\n".join(prompt_parts)

與 @commitlint/prompt-cli 整合

# 互動式提交訊息建立
npx commit

# 使用自訂設定
npx commit --config ./commitlint.config.js

# 使用指定鉤子
npx commit --hook .husky/commit-msg

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).

相關技能