diff --git a/.eslintrc.js b/.eslintrc.js index d8b44e9c6cf610..9ad3a78dd25150 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 f8a4abf95a2f57..100e92cff067e8 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 00000000000000..571451543b48c6 --- /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 86b41a24f73761..6bd1acebb741d1 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",