1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 前端工程化之commit规范(代码提交规范)

前端工程化之commit规范(代码提交规范)

时间:2021-05-23 17:32:28

相关推荐

前端工程化之commit规范(代码提交规范)

其实commit规范不管是前端还是后端也好,我觉得吧,在任何的工程化的项目中都是不可或缺的部分啦,commit 提交不规范,项目维护和管理起来是极其麻烦的,毕竟每个人都具有自己的个性,commit message的格式也是参差不齐

git 可以帮我们很好地管理代码,但是在多人合作的时候,经常会碰到各种随意的 commit message,当你需要会看 commit message 的时候,就会很头疼。

幸运的是我们可以使用工具去处理掉这个问题,不让这种小问题影响到项目的进展

第一步:安装commitlint插件和husky插件 (规范)

npm install @commitlint/cli @commitlint/config-conventional -Dnpm install husky -D

二步:将husky进行初始化

// 一定要需要git init 初始化npx husky install

第三步:生成husky配置文件

npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1'// 如果生成文件失败,则。1. npx husky add .husky/commit-msg2,将 'npx --no-install commitlint --edit $1' 粘贴到husky下的 commit-msg 文件下

第四步:生成commitlint配置文件

echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js// 在提交commit时可能会报错: SyntaxErroe: Invalid or unexpected token// 解决办法:// 这是因为配置文件的编码格式不正确:更改vscode下方编码格式改成 UTF-8

第五步:commitlint配置文件内配置提交规则

// 将以下内容替换 commitlint.config.js 内容module.exports = {extends: ["@commitlint/config-conventional"],// # 提交格式(注意冒号后面有空格)// # git commit -m <type>[optional? scope]: <description>// 例:git commit -m 'feat: 测试' rules: {'type-enum': [2, 'always', ['upd', 'feat', 'fix', 'refactor', 'docs', 'chore', 'style', 'revert']],'type-case': [0],'type-empty': [2, 'never'],'scope-empty': [0],'scope-case': [0],'subject-full-stop': [0],'subject-empty': [2, 'never'],'subject-case': [0],'header-max-length': [0]}};

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。