Anolilab 的可共享编码标准配置.
Daniel Bannert的开源工作得到了社区的支持 GitHub 赞助商
安装
npm install @anolilab/commitlint-config
yarn add @anolilab/commitlint-config
pnpm add @anolilab/commitlint-config
使用量
如果你没有 commitlint.config.js 或者其他支持的名字, 我们可以在安装后为您创建文件 @anolilab/commitlint-config电话 pnpm commitlint-config:install。 。 。 .
或者可以定义配置在一个
commitlint.config.js, (中文(简体) ),.commitlintrc.js, (中文(简体) ),.commitlintrc, (中文(简体) ),.commitlintrc.json, (中文(简体) ),.commitlintrc.yml文件
如果你已经有一个 commitlint.config.js,然后可以扩展 commitlint.config.js,与 @anolilab/commitlint-config。 。 。 .
module.exports = {
extends: ["@anolilab/commitlint-config"],
rules: {
// overwrite rules here
// or extend rules
},
};
或者说
export default {
extends: ["@anolilab/commitlint-config"],
rules: {
// overwrite rules here
// or extend rules
},
};
此扩展 @anolilab/commitlint-config 并使用它预定义的配置.
委员会规则
本配置包含以下定制规则: 1
body-leading-blank:主体和身体之间必须有空白的行.body-max-line-length:身体每行不得超过100个字符.footer-leading-blank:身体和足部之间必须有一行空白.footer-max-line-length:每行页脚不得超过100个字符.header-max-length:标题每行不得超过100个字符.scope-case:范围必须是小写并使用kebab-case.scope-empty:范围是可选的.subject-case:主体必须从大写字母开始,使用句子大小写.subject-empty: 主题需要.subject-full-stop:主题不得以一个时期结束.type-case: 类型必须是小写.type-empty: 需要该类型.type-enum: 该类型必须是下列类型之一:build: 影响构建系统或外部依赖关系的改变(例如:gulp, crancoli, npm)chore: 构建进程或辅助工具和文件生成等库的更改ci: 我们的 CI 配置文件和脚本的更改(例:Travis, Circle,浏览器Stack, SauceLabs)deps: 添加、更新或删除依赖关系的修改docs: 仅文档更改feat: 新特性fix: 错误修正perf: 改进性能的代码更改refactor: 代码更改,既不修正错误,也不添加特性revert: 恢复先前的承诺security: 代码更改可以改善安全性style:不影响代码含义的更改(白-空格,格式化,缺少分号等)test: 添加缺失的测试或更正现有测试translation: 翻译更改
所有规则从 @ commitlint/ config- 常规。 。 。 .
添加软件包.json 脚本
为运行添加国家预防机制脚本 commitlint 命令,该命令将添加 lint:commits 脚本到您的脚本部分 package.json。 。 。 .
pnpm pkg set scripts.lint:commits="pnpm commitlint --from HEAD~1 --to HEAD --verbose"
对于
npm用户,替换pnpm与npm在上述命令中.
胡斯基
安装
pnpm add -D husky is-ci
增加一个 commit-msg 锁定您的工程, 运行以下命令 :
npx husky add .husky/commit-msg 'pnpm commitlint --edit "${1}"'
还有为了 package.json数字 :
pnpm pkg set scripts.prepare="is-ci || husky install || exit 0"
对于
npm用户,替换pnpm与npm在上述命令中.
测试配置
对于承诺的第一次使用测试,您可以进行以下操作:
# using pnpm
$ pnpm commitlint --from HEAD~1 --to HEAD --verbose
# or, using npx
$ npx commitlint --from HEAD~1 --to HEAD --verbose
# or, if script was added
$ pnpm lint:commits
这将检查您最后一次承诺, 如果无效则返回错误, 如果无效则返回正输出 .
测试钩子
你可以通过承诺测试钩子。 如果承诺消息是有效的,则承诺会通过,否则你会看到错误消息.
以下是一个实例, 说明如果您的承诺消息不符合要求格式, 错误消息会是什么样子 :
$ git commit -m "foo: this will fail"
husky > commit-msg (node v10.1.0)
No staged files match any of provided globs.
⧗ input: foo: this will fail
✖ type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test] [type-enum]
✖ found 1 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
husky > commit-msg hook failed (add --no-verify to bypass)
如果承诺信息符合要求的格式,您应当看到信息 :
$ git commit -m "feat: add new feature"
husky > commit-msg (node v10.1.0)
[master 9d41607] feat: add new feature
1 file changed, 1 insertion(+)
提交
当首次安装此软件包时, 以下可共享配置 .czrc 自动添加到您的工程文件夹中 :
注意: 如果脚本检测到已有的
.czrc文件,它不会覆盖它.
说明: 邮局的脚本不运行,你就得加上
.czrc手动.
{
"path": "cz-conventional-changelog"
}
胡斯基
增加一个 prepare-commit-msg 锁定您的工程, 运行以下命令 :
npx husky add .husky/prepare-commit-msg 'exec < /dev/tty && npx cz --hook || true'
说明: 这只是一个简单的例子。 为了支持Linux,Mac和Windows上的大多数案例,您可以使用下面的另一个例子.
# if we hve a cmd that is running npx cz that means finalize and commit
FILE=commit.cmd
if test -f "$FILE"; then
echo "$FILE exists."
rm commit.cmd
exit 0;
fi
# if on Windows, spawn a cmd that will run npx cz
case `uname` in
*CYGWIN*|*MINGW*|*MSYS* )
# Only run commitizen if no commit message was already provided.
if [ -z "${2-}" ]; then
export CZ_TYPE="${CZ_TYPE:-fix}"
export CZ_MAX_HEADER_WIDTH=$COMMITLINT_MAX_WIDTH
export CZ_MAX_LINE_WIDTH=$CZ_MAX_HEADER_WIDTH
echo "npx cz && exit" > commit.cmd
start commit.cmd
exit 1;
fi
exit 0;;
esac
# Only run commitizen if no commit message was already provided.
if [ -z "${2-}" ]; then
export CZ_TYPE="${CZ_TYPE:-fix}"
export CZ_MAX_HEADER_WIDTH=$COMMITLINT_MAX_WIDTH
export CZ_MAX_LINE_WIDTH=$CZ_MAX_HEADER_WIDTH
# By default git hooks are not interactive. exec < /dev/tty allows a users terminal to interact with commitizen.
exec < /dev/tty && npx cz --hook || true
fi
这个命令允许用户使用他们的终端在钩子期间与Commitizen交互.
为什么
exec < /dev/tty?默认情况下,git hooks是不交互的.注:如果您正在使用
zsh您可能需要使用exec < /dev/tty?改为exec < /dev/tty。 。 。 .注:对于 pnpm 用户,替换
npx与pnpx在上述命令中.
祝贺你! 你的回报是友好的 是时候炫耀了!
相关
支持的节点.js版本
这一生态系统中的图书馆尽最大努力追踪 Node.js的释放时间表。 。 。 .
这里 关于为什么我们认为这很重要的文章。 。 。 .
捐款
说明: 请注意,该项目已连同《协助者行为守则》一起公布。 通过参加这个项目,你同意遵守其条款.
贷项
在阿诺利拉布制造的
这是一个开源项目,将永远可以自由使用。 如果你觉得很酷. 阿诺利拉布 是一个开发与AI工作室。 联系时间: 你好@anolilab.com 如果你需要帮助 这些技术 或者想打个招呼!
许可证
Anolilab content-config是开源软件,根据该软件许可 麻省理工学院