From ee53e4985c1f8ac6a3bb84837ce52bce796c6e8b Mon Sep 17 00:00:00 2001 From: "Jake F - @samouri" Date: Thu, 23 Mar 2017 15:48:21 -0400 Subject: [PATCH] add in precommit hook & disable all style rules from eslintrc --- .eslintrc.js | 8 ++++++-- bin/pre-commit | 6 ++++++ bin/prettify-file.sh | 15 +++++++++++++++ package.json | 2 ++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 bin/prettify-file.sh diff --git a/.eslintrc.js b/.eslintrc.js index d8b44e9c6cf61..9ad3a78dd2515 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,10 @@ module.exports = { root: true, - 'extends': 'wpcalypso/react', + 'extends': [ + 'wpcalypso/react', + 'prettier', + 'prettier/react' + ], parser: 'babel-eslint', env: { browser: true, @@ -17,4 +21,4 @@ module.exports = { 'no-restricted-modules': [ 2, 'lib/sites-list', 'lib/mixins/data-observe' ], 'no-unused-expressions': 0, // Allows Chai `expect` expressions } -}; \ No newline at end of file +}; diff --git a/bin/pre-commit b/bin/pre-commit index f8a4abf95a2f5..100e92cff067e 100755 --- a/bin/pre-commit +++ b/bin/pre-commit @@ -12,6 +12,12 @@ fi pass=true +printf "\nFormatting .jsx and .js:\n" + +for file in ${files}; do + ./bin/prettify-file.sh ${file} +done + printf "\nValidating .jsx and .js:\n" ./bin/run-lint $(git diff --cached --name-only client/ server/ test/ | grep ".jsx*$") -- --diff=index diff --git a/bin/prettify-file.sh b/bin/prettify-file.sh new file mode 100644 index 0000000000000..571451543b48c --- /dev/null +++ b/bin/prettify-file.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +file="$1" +printf $file +if [[ ! $file =~ ^client/[^\.]+\.jsx?$ ]]; then + printf "\nNot a prettifiable file\n" + exit 0 +fi + +if [ ! -f ./node_modules/.bin/prettier ]; then + printf "\n'Prettier' not found, please run 'npm install' first\n" + exit 1 +fi + +./node_modules/.bin/prettier --print-width=100 --single-quote --tab-width=4 --trailing-comma=es5 --write ${file} diff --git a/package.json b/package.json index 86b41a24f7376..6bd1acebb741d 100644 --- a/package.json +++ b/package.json @@ -168,6 +168,7 @@ "esformatter-special-bangs": "1.0.1", "eslines": "0.0.11", "eslint": "3.8.1", + "eslint-config-prettier": "1.5.0", "eslint-config-wpcalypso": "0.6.0", "eslint-plugin-react": "6.4.1", "eslint-plugin-wpcalypso": "3.0.2", @@ -180,6 +181,7 @@ "mockery": "1.7.0", "nock": "8.0.0", "nodemon": "1.4.1", + "prettier": "0.22.0", "react-addons-test-utils": "15.4.0", "react-hot-loader": "1.3.0", "react-test-env": "0.2.0",