概念:可共享配置
¥Concept: Shareable configuration
最常见的可共享配置以 npm 包的形式提供,默认导出一个包含 .rules
的对象。要使用共享配置,请将其指定为 .extends
数组中的项:
¥Most commonly shareable configuration is delivered as npm package exporting an object containing .rules
as default. To use shared configuration you specify it as item in the .extends
array:
/**
* @type {import('@commitlint/types').UserConfig}
*/
export default {
extends: ["example"], // => commitlint-config-example
};
这会导致 commitlint
拾取 commitlint-config-example
。通过安装使其可用。
¥This causes commitlint
to pick up commitlint-config-example
. Make it available by installing it.
npm install --save-dev commitlint-config-example
在 commitlint-config-example
中找到的规则将与 commitlint.config.js
中的规则(如果有)合并。
¥The rules found in commitlint-config-example
are merged with the rules in commitlint.config.js
, if any.
此操作以递归方式运行,使可共享配置能够扩展到无限长的其他可共享配置链上。
¥This works recursively, enabling shareable configuration to extend on an indefinite chain of other shareable configurations.
相对配置
¥Relative config
你还可以使用文件的相对路径加载本地配置。
¥You can also load local configuration by using a relative path to the file.
警告
此操作必须始终以 .
(点)开头。
¥This must always start with a .
(dot).
export default {
extends: ["./example"], // => ./example.js
};
作用域包
¥Scoped packages
使用作用域包时,你有两个选择。
¥When using scoped packages you have two options.
你可以提供包的完整路径,例如:
¥You can provide the full path of the package like:
export default {
extends: ["@commitlint/config-conventional"], // => @commitlint/config-conventional
};
或者仅仅是包的作用域/所有者。
¥Or just the scope/owner of the package.
[!TIP]
就像上面列出的 "normal" 扩展一样,这将添加
<scope>/commitlint-config
。¥Just like "normal" extends listed above, this will add
<scope>/commitlint-config
.
export default {
extends: ["@coolcompany"], // => @coolcompany/commitlint-config
};
如果你未使用完全相同的 <scope>/commitlint-config
模式,则必须提供软件包的全名。
¥If you don't use the exact <scope>/commitlint-config
pattern, you have to provide the full name of the package.