From ea61d9878fdd23a80015e63f06d8fe749a4ff097 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 25 Nov 2016 13:16:11 -0500 Subject: [PATCH] add pre-commit hook --- .github/CONTRIBUTING.md | 8 ++++++++ build/git-hooks/pre-commit | 7 +++++++ package.json | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100755 build/git-hooks/pre-commit diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index a167e76dbd1..16fe5b56156 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -59,6 +59,14 @@ After cloning the repo, run: $ npm install ``` +If you are on a Unix-like system, optionally install the Git pre-commit hook with: + +``` bash +$ npm run install:hooks +``` + +This will run Flow and ESLint on changed files before each commit. + ### Commonly used NPM scripts ``` bash diff --git a/build/git-hooks/pre-commit b/build/git-hooks/pre-commit new file mode 100755 index 00000000000..41fecbfa8ae --- /dev/null +++ b/build/git-hooks/pre-commit @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +files_to_lint=$(git diff --cached --name-only --diff-filter=ACM | grep '\.js$') + +if [ -n "$files_to_lint" ]; then + flow && NODE_ENV=production eslint $files_to_lint +fi diff --git a/package.json b/package.json index c7c49e85332..5ee7b47faab 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "sauce": "SAUCE=true karma start build/karma.sauce.config.js", "bench:ssr": "npm run build:ssr && NODE_ENV=production node benchmarks/ssr/renderToString.js && NODE_ENV=production VUE_ENV=server node benchmarks/ssr/renderToStream.js", "release": "bash build/release.sh", - "release:weex": "bash build/release-weex.sh" + "release:weex": "bash build/release-weex.sh", + "install:hooks": "ln -fs ../../build/git-hooks/pre-commit .git/hooks/pre-commit" }, "repository": { "type": "git",