配置
¥Configuration
通过文件配置
¥Config via file
@commitlint/cli
从以下文件中获取配置:
¥@commitlint/cli
picks up configuration from the following files:
.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
预期文件
¥The file is expected
包含有效的 JavaScript/Typescript。
¥to contain valid JavaScript / Typescript
导出配置对象
¥export a configuration object
遵循以下概述的架构。
¥adhere to the schema outlined below
配置文件使用 cosmiconfig 解析。
¥Configuration files are resolved using cosmiconfig.
通过 package.json
配置
¥Config via package.json
你可以在 package.json
(或 package.yaml
)中添加一个 commitlint
字段,其对象遵循以下结构。
¥You can add a commitlint
field in package.json
(or package.yaml
) with an object that follows the below structure.
配置选项 CLI
¥Config option CLI
添加配置文件的路径。示例:commitlint --config commitlint.config.js
¥Add the path to the configuration file. Example: commitlint --config commitlint.config.js
配置对象示例
¥Configuration object example
const Configuration = {
/*
* Resolve and load @commitlint/config-conventional from node_modules.
* Referenced packages must be installed
*/
extends: ["@commitlint/config-conventional"],
/*
* Resolve and load conventional-changelog-atom from node_modules.
* Referenced packages must be installed
*/
parserPreset: "conventional-changelog-atom",
/*
* Resolve and load @commitlint/format from node_modules.
* Referenced package must be installed
*/
formatter: "@commitlint/format",
/*
* Any rules defined here will override rules from @commitlint/config-conventional
*/
rules: {
"type-enum": [2, "always", ["foo"]],
},
/*
* Array of functions that return true if commitlint should ignore the given message.
* Given array is merged with predefined functions, which consist of matchers like:
* * - 'Merge pull request', 'Merge X into Y' or 'Merge branch X'
* - 'Revert X'
* - 'v1.2.3' (ie semver matcher)
* - 'Automatic merge X' or 'Auto-merged X into Y'
* * To see full list, check https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/is-ignored/src/defaults.ts.
* To disable those ignores and run rules always, set `defaultIgnores: false` as shown below.
*/
ignores: [(commit) => commit === ""],
/*
* Whether commitlint uses the default ignore rules, see the description above.
*/
defaultIgnores: true,
/*
* Custom URL to show upon failure
*/
helpUrl:
"https://github.com/conventional-changelog/commitlint/#what-is-commitlint",
/*
* Custom prompt configs
*/
prompt: {
messages: {},
questions: {
type: {
description: "please input type:",
},
},
},
};
export default Configuration;
也支持 CJS 格式:
¥[!NOTE] CJS format is supported as well:
module.exports = Configuration;
Typescript 配置
¥Typescript configuration
配置也可以是 TypeScript 文件。
¥Configuration can also be a typescript file.
可以从 @commitlint/types
导入相关类型和枚举。
¥Relevant types and enums can be imported from @commitlint/types
.
下面你可以看到与标准 js 文件相比的主要变化:
¥Below you can see main changes from a standard js file:
import type { UserConfig } from "@commitlint/types";
import { RuleConfigSeverity } from "@commitlint/types";
const Configuration: UserConfig = {
extends: ["@commitlint/config-conventional"],
parserPreset: "conventional-changelog-atom",
formatter: "@commitlint/format",
rules: {
"type-enum": [RuleConfigSeverity.Error, "always", ["foo"]],
},
// ...
};
export default Configuration;
可共享配置
¥Shareable configuration
每个 commitlint 配置都可以扩展其他 commitlint 配置。通过 .extends
键指定要扩展的配置,并使用节点解析算法可解析的 ID。
¥Every commitlint configuration can extend other commitlint configurations. Specify configurations to extend via the .extends
key, using ids that can be resolved by the node resolve algorithm.
这意味着可以使用已安装的 npm 包和本地文件。
¥This means installed npm packages and local files can be used.
npm install --save-dev commitlint-config-lerna @commitlint/config-conventional
export default {
extends: [
'lerna' // prefixed with commitlint-config-*,
'@commitlint/config-conventional' // scoped packages are not prefixed
]
}
更多信息可以在 概念 – 可共享配置部分 中找到。
¥More information can be found in the Concepts – shareable config section.
解析器预设
¥Parser presets
用于解析提交消息的解析器预设可以配置。使用节点解析算法可解析的 ID。
¥The parser preset used to parse commit messages can be configured. Use ids resolvable by the node resolve algorithm.
这意味着可以使用已安装的 npm 包和本地文件。
¥This means installed npm packages and local files can be used.
npm install --save-dev conventional-changelog-atom
export default {
parserPreset: "conventional-changelog-atom",
};
格式化程序
¥Formatter
如果需要,Commitlint 可以以不同的格式输出遇到的问题。使用节点解析算法可解析的 ID。
¥Commitlint can output the issues encountered in different formats, if necessary. Use ids resolvable by the node resolve algorithm.
export default {
formatter: "@commitlint/format",
};
规则
¥Rules
请参阅 规则 获取可用规则的完整列表。
¥Refer to Rules for a complete list of available rules.
提示
¥Prompt
配置命令行提交交互,与 @commitlint/cz-commitlint
配合使用。
¥Config command-line submit interaction, works with @commitlint/cz-commitlint
.
请参阅 提示配置 获取详情。
¥Refer to Prompt Config for details.