1.1.0 • Published 2 years ago

githook-code-filter v1.1.0

Weekly downloads
1
License
ISC
Repository
-
Last release
2 years ago

在git commit前检测代码

在nodejs项目中的app.js文件中引入:
    const setCommitCheck = require('githook-code-filter');
    setCommitCheck([config]);
其中config为可选参数,代表校验规则。建议传入适用于自己需求的规则。

注意

1、.git/hooks/pre-commit文件不存在时会创建,存在会替换掉旧文件
2、需要先运行一次代码(node app.js),去触发文件的创建,该npm包才能生效
3、config为可选参数,具体格式如下:
    a、是一个对象
    b、对象中key值必须包含有js、css、html三个key
    c、每一个key值对应的均为数组,如不需要对该类文件做校验,仍需定义空数组
    d、数组中每一项为对象,至少包含rule属性,为正则规则,注意:对带有反斜杠的\需要转义
    e、note属性为可选属性,可自定义拦截后的输出提示信息
    f、目前js、css、html三个key分别对应支持检测css|scss|less、js|es、html|hb类型文件
        {
            "js": [{
                "rule": "/console/",
                "note": "请去除js文件中多余的console.log信息"
            }, {
                "rule": "/alert/",
                "note": "请使用其他方式代替alert输出信息"
            }, {
                "rule": "/error/",
                "note": ""
            }],
            "css": [{
                "rule": "/display:\\s*table/",
                "note": "table布局过于耗费性能,请用其他方式代替"
            }],
            "html": [],
        }

历史版本

版本说明
1.0.0feat:初步搭建可供应用的git commit拦截功能(存在关键性bug)
1.1.0fix:修复 git commit 时,符合所有规则也无法正常提交的bug