Last active
November 23, 2018 09:01
-
-
Save xiaoshude/a8cd454383f3f86423a271f0d76d0da1 to your computer and use it in GitHub Desktop.
为项目添加 lint 和 commit msg 检查
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/build/ | |
/config/ | |
/dist/ | |
/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://eslint.org/docs/user-guide/configuring | |
module.exports = { | |
root: true, | |
parserOptions: { | |
parser: 'babel-eslint' | |
}, | |
env: { | |
browser: true, | |
}, | |
extends: [ | |
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention | |
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules. | |
'plugin:vue/essential', | |
// https://github.com/standard/standard/blob/master/docs/RULES-en.md | |
'standard' | |
], | |
// required to lint *.vue files | |
plugins: [ | |
'vue' | |
], | |
// add your custom rules here | |
rules: { | |
// allow async-await | |
'generator-star-spacing': 'off', | |
// allow debugger during development | |
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off' | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "demo", | |
"description": "A Vue.js project", | |
"scripts": { | |
"lint": "eslint --ext .js,.vue src", | |
"lint-fix": "eslint --ext .js,.vue src --fix" | |
}, | |
"gitHooks": { | |
"pre-commit": "lint-staged", | |
"commit-msg": "node scripts/verify-commit-msg.js" | |
}, | |
"lint-staged": { | |
"*.{js,vue}": [ | |
"eslint --fix", | |
"git add" | |
] | |
}, | |
"dependencies": { | |
"vue": "^2.5.16", | |
"vue-router": "^3.0.1", | |
"vuex": "^3.0.1" | |
}, | |
"engines": { | |
"node": ">=6" | |
}, | |
"devDependencies": { | |
"eslint": "^4.15.0", | |
"eslint-config-standard": "^10.2.1", | |
"eslint-friendly-formatter": "^3.0.0", | |
"eslint-loader": "^1.7.1", | |
"eslint-plugin-import": "^2.7.0", | |
"eslint-plugin-node": "^5.2.0", | |
"eslint-plugin-promise": "^3.4.0", | |
"eslint-plugin-standard": "^3.0.1", | |
"eslint-plugin-vue": "^4.0.0", | |
"lint-staged": "^7.0.0", | |
"yorkie": "^1.0.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const chalk = require('chalk') | |
const msgPath = process.env.GIT_PARAMS | |
const msg = require('fs').readFileSync(msgPath, 'utf-8').trim() | |
const commitRE = /^(revert: )?(feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types|build)(\(.+\))?: .{1,50}/ | |
if (!commitRE.test(msg)) { | |
console.log() | |
console.error( | |
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(`invalid commit message format.`)}\n\n` + | |
chalk.red(` Proper commit message format is required for automated changelog generation. Examples:\n\n`) + | |
` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` + | |
` ${chalk.green(`fix(v-model): handle events on blur (close #28)`)}\n\n` + | |
chalk.red(` See .github/COMMIT_CONVENTION.md for more details.\n`) + | |
chalk.red(` You can also use ${chalk.cyan(`npm run commit`)} to interactively generate a commit message.\n`) | |
) | |
process.exit(1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment