git hooks
Closed this issue · 3 comments
holyzfy commented
TODO
- 提交日志不能为空
- 校验文件名
- 校验js
- 全局变量
- 命名习惯
- no-alert, no-console
- 连续的空行请合并成一个空行
- 校验css
- empty-rules
- duplicate-properties
- universal-selector
- ids
holyzfy commented
.eslintignore
/js/lib/
/build/
/test/
/build.js
# 忽略vm的模拟数据
/*.js
.eslintrc.json
{
"env": {
"browser": true,
"amd": true
},
"globals": {
"app": true,
"require": true
},
"rules": {
"semi": "error",
"no-console": "error",
"no-alert": "error",
"no-dupe-keys": "error",
"curly": ["error", "multi-line"],
"no-extra-semi": "error",
"no-inner-declarations": "error",
"no-unreachable": "error",
"valid-typeof": "error",
"array-callback-return": "error",
"no-else-return": "warn",
"no-extend-native": "error",
"no-implicit-globals": "error",
"no-loop-func": "warn",
"no-return-assign": "warn",
"no-unmodified-loop-condition": "warn",
"no-unused-expressions": ["warn", { "allowShortCircuit": true, "allowTernary": true }],
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"camelcase": ["error", {"properties": "never"}],
"lines-around-comment": ["warn", { "beforeLineComment": true, "beforeBlockComment": true, "allowBlockStart": true }],
"max-params": ["warn", { "maximum": 4}],
"new-cap": ["warn", { "newIsCap": true, "capIsNew": false }],
"no-multiple-empty-lines": ["error", {"max": 1}]
}
}
holyzfy commented
package.json
{
// ...
"scripts": {
"validate_filename": "validate_filename -e '^[a-z0-9\\-_./]+$' -m '约定文件名由小写字母、数字、_组成' `git diff --staged --name-only --diff-filter=ACMRTU`",
"csslint": "files=`git diff --staged --name-only --diff-filter=ACMRTU | grep -ie '\\.css$'`; if [ \"${files:=empty}\" != \"empty\" ]; then csslint --quiet $files; fi",
"eslint": "files=`git diff --staged --name-only --diff-filter=ACMRTU | grep -ie '\\.js$'`; if [ \"${files:=empty}\" != \"empty\" ]; then eslint -c .eslintrc.json $files; fi",
"build": "node ./node_modules/requirejs/bin/r.js -o build.js"
},
"config": {
"ghooks": {
"pre-commit": "npm run validate_filename && npm run csslint && npm run eslint"
}
},
"devDependencies": {
"ghooks": "^1.0.3"
}
// ...
}
安装
npm install -g validate_filename csslint eslint
npm install
holyzfy commented
.csslintrc
--errors=empty-rules,duplicate-properties,universal-selector,ids