首页 > 其他分享 >Husky + Commitlint实现commit message校验

Husky + Commitlint实现commit message校验

时间:2023-04-19 23:26:23浏览次数:27  
标签:npm Husky 校验 husky commit message config commitlint

配置git提交的校验钩子

  • husky:git 提交时触发hooks
  • commitlint: 对提交的内容做规范校验husky,主要对pre-commit和commit-msg钩子做校验
# 安装husky
 npm install husky -D

# 初始化husky配置,在根目录新增.husky配置文件。初始化配置pre-commit

npx husky-init

#另外新增一个hooks,commit-log

npx husky add .husky/commit-msg

目录结构这样的

 在 commit-msg文件中添加 npm run commitlint

在pre-commit 文件中有个npm run test我们先注释掉,不然会报错

安装commitlint

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

  

配置scripts

因为我们要运行npm run commitlint,所以在package.json文件中添加

"scripts": {
    "commitlint": "commitlint --config commitlint.config.js -e -V"
  },

 在commit-msg中添加npm run commitlint

 

 

然后我们在根目录新建commitlint.config.js

module.exports = {
  ignores: [(commit) => commit.includes("build")],
  extends: ["@commitlint/config-conventional"],
  rules: {
    "body-leading-blank": [2, "always"],
    "footer-leading-blank": [1, "always"],
    "header-max-length": [2, "always", 108],
    "subject-empty": [2, "never"],
    "type-empty": [2, "never"],
    "type-enum": [2, "always", ["merge", "feat", "fix", "perf", "style", "docs", "test", "refactor", "build", "ci", "chore", "revert", "wip", "workflow", "types", "release", "build"]]
  }
};

 以上简单的husky配置完成了,我们简单测试下

 再次添加前缀,commit成功

 

标签:npm,Husky,校验,husky,commit,message,config,commitlint
From: https://www.cnblogs.com/chailuG/p/17335050.html

相关文章

  • git如何找出两个分支的共同commit点
    gitmerge-base[-a|--all]<commit><commit>…​gitmerge-base[-a|--all]--octopus<commit>…​gitmerge-base--is-ancestor<commit><commit>gitmerge-base--independent<commit>…​gitmerge-base--fork-point<ref......
  • 【vue3-element-admin】Husky + Lint-staged + Commitlint + Commitizen + cz-git 配
    前言本文介绍vue3-element-admin如何通过Husky+Lint-staged+Commitlint+Commitizen+cz-git来配置Git提交代码规范。核心内容是配置Husky的pre-commit和commit-msg两个钩子:pre-commit:Husky+Lint-staged整合实现Git提交前代码规范检测/格式化(前提......
  • 判断页面是否有window、messager显示
    判断页面是否有window、message显示/** *页面是否已经打开window框 */ functionhasWindow(){ varlen=$(".messager-body").length; if(len==0){ returnfalse; }else{ returntrue; } }//$.data($(".messager-body").get(0),'window')判断缓......
  • gdbusmessage.c
    /*GDBus-GLibD-BusLibrary**Copyright(C)2008-2010RedHat,Inc.**Thislibraryisfreesoftware;youcanredistributeitand/or*modifyitunderthetermsoftheGNULesserGeneralPublic*LicenseaspublishedbytheFreeSoftwareFounda......
  • git中 commit 和 pull 的先后顺序问题会产生多余的merge记录
    commit和pull的先后顺序问题最近提交代码,发现一个问题。自己很清楚的记得本次的提交是没有进行合并的。奇怪的死gitlab中的history历史中显示了我对本次进行了Merge合并操作。并且Merge合并操作中显示了很多不是本次对代码的修改。这就很明显了,git自动生成的merge操......
  • org.apache.flume.ChannelFullException: Space for commit to queue couldn't be acq
    做以下修改agent.channels.memoryChanne3.keep-alive=60agent.channels.memoryChanne3.capacity=1000000修改java最大内存大小vibin/flume-ngJAVA_OPTS="-Xmx2048m"参考http://fangjian0423.github.io/2016/01/19/flume-channel-full-exception/......
  • [git] 规范Commit格式
    规范Commit格式Jenkins根据对比当次构建和上次构建的Commit信息来生成ChangeLog,但因为我们目前的提交不够规范,经常有类似"#","update"这列的提交,无法提供给PM有效的更新记录,所以建议大家尽量规范Commit格式。ConventionalCommits目前推荐大家是有这套规范,如果大家有更好的可以......
  • POJ 2774 Long Long Message (后缀数组)
    题目地址:POJ2774后缀数组第一发!后缀数组真是太神奇了。。(好像每学一种新算法我都会这么说。。原理研究了好长时间,还有代码的实现,论文作者罗穗骞的代码太简洁。。好难看懂QAQ,看了好长时间。来一发后缀数组模板题,模板是用的倍增思想。代码如下:#include<iostream>#include......
  • 取消git提交时precommit代码校验
    用git进行代码管理,当我执行gitcommit操作时,会出现一下代码来检测提交的代码Pro:hcf-vuehh$gitadd--allPro:hcf-vuehh$gitcommit-m'wq'husky>pre-commit(nodev8.11.2)❯Runningtasksforsrc/**/*.{js,jsx,vue}⠼eslint解决办法:1.进入项目所在文......
  • MFC-RegisterWindowMessage给窗口增加一个消息
     UINTshowMyAppMsg=RegisterWindowMessage(_T("MYAPP_SHOW"));//给窗口增加一个消息/*定义一个新的窗口消息,保证该消息在系统范围内是唯一的。通常调用SendMessage或者PostMessage函数时,可以使用该函数返回的消息值参数:LPCTSTRlpString消息字符串......