From 9847cdb82f458512b2a649aa292dc29affb6906d Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Tue, 19 Jun 2018 09:33:48 +0200 Subject: [PATCH] build(lint): auto code formatting with prettier Currently we use eslint to lint code, but formatting the code according to our ruleset is a manual process. Implement `prettier` so that code is automatically formatted as part of our development workflow. See https://prettier.io/ --- .eslintrc | 51 +++++++++-------- .prettierignore | 22 ++++++++ .prettierrc | 15 +++++ package.json | 17 ++++-- yarn.lock | 142 +++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 218 insertions(+), 29 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.eslintrc b/.eslintrc index ebbde954..1c2c523c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,7 +12,11 @@ "plugin:import/errors", "plugin:import/warnings", "plugin:jsx-a11y/strict", - "plugin:promise/recommended" + "plugin:promise/recommended", + "prettier", + "prettier/flowtype", + "prettier/react", + "plugin:prettier/recommended" ], "env": { "browser": true, @@ -21,42 +25,45 @@ "rules": { "comma-dangle": ["error", "never"], "semi": ["error", "never"], - "indent": 2, - "jsx-quotes": ["error", "prefer-single"], + "prettier/prettier": "error", "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], "react/no-did-mount-set-state": 0, "jsx-a11y/no-static-element-interactions": 0, "jsx-a11y/no-noninteractive-element-interactions": 0, "jsx-a11y/click-events-have-key-events": 0, - "jsx-a11y/label-has-for": [ 2, { - "components": [ "Label" ], - "required": { - "every": [ "id" ] - }, - "allowChildren": false - }], + "jsx-a11y/label-has-for": [ + 2, + { + "components": ["Label"], + "required": { + "every": ["id"] + }, + "allowChildren": false + } + ], "react/no-array-index-key": 0, "react/forbid-prop-types": 0, "camelcase": 0, + "curly": ["error", "all"], "react/require-default-props": 0, - "max-len": ["error", 150], + "max-len": ["error", { "code": 150, "ignoreUrls": true }], "import/no-extraneous-dependencies": 0, + "no-confusing-arrow": "error", + "no-mixed-operators": "error", "no-new": 0, + "no-tabs": "error", "compat/compat": "error", - "prefer-destructuring": ["error", { - "array": false, - "object": true - }], + "prefer-destructuring": [ + "error", + { + "array": false, + "object": true + } + ], "prefer-promise-reject-errors": 0, "no-param-reassign": [2, { "props": false }] }, - "plugins": [ - "flowtype", - "import", - "promise", - "compat", - "react" - ], + "plugins": ["flowtype", "import", "json", "markdown", "prettier", "promise", "compat", "react"], "settings": { "import/resolver": { "node": { diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..f0cfe5cf --- /dev/null +++ b/.prettierignore @@ -0,0 +1,22 @@ +# App source +package.json +package-lock.json +.git +.babelrc +node_modules +coverage + + +# App packaged +release +app/main.prod.js +app/main.prod.js.map +app/renderer.prod.js +app/renderer.prod.js.map +app/style.css +app/style.css.map +app/utils/bech32.js +dist +dll +main.js +main.js.map diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..201a0be2 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,15 @@ +{ + "bracketSpacing": true, + "printWidth": 150, + "semi": false, + "singleQuote": true, + "trailingComma": "none", + "overrides": [ + { + "files": [".babelrc", ".commitlintrc", ".eslintrc", ".huskyrc", ".lintstagedrc", ".prettierrc", ".stylelintrc"], + "options": { + "parser": "json" + } + } + ] +} diff --git a/package.json b/package.json index 1cd159b3..bb38b072 100644 --- a/package.json +++ b/package.json @@ -11,11 +11,15 @@ "dev": "cross-env START_HOT=1 npm run start-renderer-dev", "flow": "flow", "flow-typed": "rimraf flow-typed/npm && flow-typed install --overwrite || true", - "lint": "cross-env NODE_ENV=development eslint --cache --format=node_modules/eslint-formatter-pretty .", + "lint-base": "eslint --cache --format=node_modules/eslint-formatter-pretty", + "lint": "npm run lint-base -- .", + "lint-fix-base": "npm run lint-base -- --fix", + "lint-fix": "npm run lint-fix-base -- \"./**/*.{js,json,md}\"", + "lint-styles-base": "stylelint --syntax scss", + "lint-styles": "npm run lint-styles-base -- app/*.scss app/components/*.scss", + "lint-styles-fix-base": "npm run lint-styles-base -- --fix", + "lint-styles-fix": "npm run lint-styles-fix-base -- app/*.scss app/components/*.scss", "lint-ci": "npm run lint && npm run lint-styles && npm run flow", - "lint-fix": "npm run lint -- --fix", - "lint-styles": "stylelint app/*.scss app/components/*.scss --syntax scss", - "lint-styles-fix": "stylelint --fix app/*.scss app/components/*.scss --syntax scss", "package": "npm run build && build --publish never", "package-all": "npm run build && build -mwl", "package-linux": "npm run build && build --linux", @@ -164,13 +168,17 @@ "enzyme-to-json": "^1.5.1", "eslint": "^4.19.1", "eslint-config-airbnb": "^16.1.0", + "eslint-config-prettier": "^2.9.0", "eslint-formatter-pretty": "^1.3.0", "eslint-import-resolver-webpack": "^0.10.0", "eslint-plugin-compat": "^2.4.0", "eslint-plugin-flowtype": "^2.49.3", "eslint-plugin-import": "^2.12.0", "eslint-plugin-jest": "^21.17.0", + "eslint-plugin-json": "^1.2.0", "eslint-plugin-jsx-a11y": "6.0.3", + "eslint-plugin-markdown": "^1.0.0-beta.6", + "eslint-plugin-prettier": "^2.6.0", "eslint-plugin-promise": "^3.8.0", "eslint-plugin-react": "^7.9.1", "express": "^4.15.3", @@ -186,6 +194,7 @@ "jsdom": "^11.0.0", "minimist": "^1.2.0", "node-sass": "^4.9.0", + "prettier": "^1.13.5", "ps-node": "^0.1.6", "react-addons-test-utils": "^15.6.0", "react-test-renderer": "^15.6.1", diff --git a/yarn.lock b/yarn.lock index 823f33ab..4cc94918 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2499,6 +2499,13 @@ cli-width@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.1.0.tgz#b234ca209b29ef66fc518d9b98d5847b00edf00a" +cli@~1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/cli/-/cli-1.0.1.tgz#22817534f24bfa4950c34d532d48ecbc621b8c14" + dependencies: + exit "0.1.2" + glob "^7.1.1" + cliui@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cliui/-/cliui-2.1.0.tgz#4b475760ff80264c762c3a1719032e91c7fea0d1" @@ -2755,7 +2762,7 @@ connected-domain@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/connected-domain/-/connected-domain-1.0.0.tgz#bfe77238c74be453a79f0cb6058deeb4f2358e93" -console-browserify@^1.1.0: +console-browserify@1.1.x, console-browserify@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.1.0.tgz#f0241c45730a9fc6323b206dbf38edc741d0bb10" dependencies: @@ -3529,6 +3536,12 @@ domhandler@2.1: dependencies: domelementtype "1" +domhandler@2.3: + version "2.3.0" + resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-2.3.0.tgz#2de59a0822d5027fabff6f032c2b25a2a8abe738" + dependencies: + domelementtype "1" + domhandler@^2.3.0: version "2.4.1" resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-2.4.1.tgz#892e47000a99be55bbf3774ffea0561d8879c259" @@ -3541,7 +3554,7 @@ domutils@1.1: dependencies: domelementtype "1" -domutils@1.5.1, domutils@^1.5.1: +domutils@1.5, domutils@1.5.1, domutils@^1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.5.1.tgz#dcd8488a26f563d61079e48c9f7b7e32373682cf" dependencies: @@ -3902,6 +3915,10 @@ enhanced-resolve@~0.9.0: memory-fs "^0.2.0" tapable "^0.1.8" +entities@1.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/entities/-/entities-1.0.0.tgz#b2987aa3821347fcde642b24fdfc9e4fb712bf26" + entities@^1.1.1, entities@~1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0" @@ -4056,6 +4073,12 @@ eslint-config-airbnb@^16.1.0: dependencies: eslint-config-airbnb-base "^12.1.0" +eslint-config-prettier@^2.9.0: + version "2.9.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-2.9.0.tgz#5ecd65174d486c22dff389fe036febf502d468a3" + dependencies: + get-stdin "^5.0.1" + eslint-formatter-pretty@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/eslint-formatter-pretty/-/eslint-formatter-pretty-1.3.0.tgz#985d9e41c1f8475f4a090c5dbd2dfcf2821d607e" @@ -4130,6 +4153,12 @@ eslint-plugin-jest@^21.17.0: version "21.17.0" resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-21.17.0.tgz#fdb00e2f9ff16987d6ebcf2c75c7add105760bbb" +eslint-plugin-json@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-json/-/eslint-plugin-json-1.2.0.tgz#9ba73bb0be99d50093e889f5b968463d2a30efae" + dependencies: + jshint "^2.8.0" + eslint-plugin-jsx-a11y@6.0.3: version "6.0.3" resolved "https://registry.yarnpkg.com/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.0.3.tgz#54583d1ae442483162e040e13cc31865465100e5" @@ -4142,6 +4171,21 @@ eslint-plugin-jsx-a11y@6.0.3: emoji-regex "^6.1.0" jsx-ast-utils "^2.0.0" +eslint-plugin-markdown@^1.0.0-beta.6: + version "1.0.0-beta.6" + resolved "https://registry.yarnpkg.com/eslint-plugin-markdown/-/eslint-plugin-markdown-1.0.0-beta.6.tgz#d9e62666eea4e76387e85f502df668abdfbd4395" + dependencies: + object-assign "^4.0.1" + remark-parse "^3.0.0" + unified "^6.1.2" + +eslint-plugin-prettier@^2.6.0: + version "2.6.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-2.6.0.tgz#33e4e228bdb06142d03c560ce04ec23f6c767dd7" + dependencies: + fast-diff "^1.1.1" + jest-docblock "^21.0.0" + eslint-plugin-promise@^3.8.0: version "3.8.0" resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.8.0.tgz#65ebf27a845e3c1e9d6f6a5622ddd3801694b621" @@ -4317,7 +4361,7 @@ exenv@^1.2.0: version "1.2.2" resolved "https://registry.yarnpkg.com/exenv/-/exenv-1.2.2.tgz#2ae78e85d9894158670b03d47bec1f03bd91bb9d" -exit@^0.1.2: +exit@0.1.2, exit@0.1.x, exit@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c" @@ -4526,6 +4570,10 @@ fast-deep-equal@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" +fast-diff@^1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.1.2.tgz#4b62c42b8e03de3f848460b639079920695d0154" + fast-glob@^2.0.2: version "2.2.2" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-2.2.2.tgz#71723338ac9b4e0e2fff1d6748a2a13d5ed352bf" @@ -4982,6 +5030,10 @@ get-stdin@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe" +get-stdin@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398" + get-stdin@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b" @@ -5503,6 +5555,16 @@ html-webpack-plugin@^3.2.0: toposort "^1.0.0" util.promisify "1.0.0" +htmlparser2@3.8.x: + version "3.8.3" + resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.8.3.tgz#996c28b191516a8be86501a7d79757e5c70c1068" + dependencies: + domelementtype "1" + domhandler "2.3" + domutils "1.5" + entities "1.0" + readable-stream "1.1" + htmlparser2@^3.9.1, htmlparser2@^3.9.2: version "3.9.2" resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.9.2.tgz#1bdf87acca0f3f9e53fa4fcceb0f4b4cbb00b338" @@ -6359,6 +6421,10 @@ jest-diff@^23.0.1: jest-get-type "^22.1.0" pretty-format "^23.0.1" +jest-docblock@^21.0.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.2.0.tgz#51529c3b30d5fd159da60c27ceedc195faf8d414" + jest-docblock@^23.0.1: version "23.0.1" resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-23.0.1.tgz#deddd18333be5dc2415260a04ef3fce9276b5725" @@ -6688,6 +6754,19 @@ jsesc@~0.5.0: version "0.5.0" resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" +jshint@^2.8.0: + version "2.9.5" + resolved "https://registry.yarnpkg.com/jshint/-/jshint-2.9.5.tgz#1e7252915ce681b40827ee14248c46d34e9aa62c" + dependencies: + cli "~1.0.0" + console-browserify "1.1.x" + exit "0.1.x" + htmlparser2 "3.8.x" + lodash "3.7.x" + minimatch "~3.0.2" + shelljs "0.3.x" + strip-json-comments "1.0.x" + json-parse-better-errors@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.1.tgz#50183cd1b2d25275de069e9e71b467ac9eab973a" @@ -7107,6 +7186,10 @@ lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" +lodash@3.7.x: + version "3.7.0" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.7.0.tgz#3678bd8ab995057c07ade836ed2ef087da811d45" + lodash@=3.10.1: version "3.10.1" resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" @@ -8718,6 +8801,10 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" +prettier@^1.13.5: + version "1.13.5" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.5.tgz#7ae2076998c8edce79d63834e9b7b09fead6bfd0" + pretty-bytes@^1.0.2: version "1.0.4" resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-1.0.4.tgz#0a22e8210609ad35542f8c8d5d2159aff0751c84" @@ -9214,6 +9301,15 @@ readable-stream@1.0: isarray "0.0.1" string_decoder "~0.10.x" +readable-stream@1.1: + version "1.1.13" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.1.13.tgz#f6eef764f514c89e2b9e23146a75ba106756d23e" + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "0.0.1" + string_decoder "~0.10.x" + readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.1.5, readable-stream@^2.2.6, readable-stream@^2.2.9: version "2.2.11" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.11.tgz#0796b31f8d7688007ff0b93a8088d34aa17c0f72" @@ -9427,6 +9523,27 @@ relateurl@0.2.x: version "0.2.7" resolved "https://registry.yarnpkg.com/relateurl/-/relateurl-0.2.7.tgz#54dbf377e51440aca90a4cd274600d3ff2d888a9" +remark-parse@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/remark-parse/-/remark-parse-3.0.1.tgz#1b9f841a44d8f4fbf2246850265459a4eb354c80" + dependencies: + collapse-white-space "^1.0.2" + has "^1.0.1" + is-alphabetical "^1.0.0" + is-decimal "^1.0.0" + is-whitespace-character "^1.0.0" + is-word-character "^1.0.0" + markdown-escapes "^1.0.0" + parse-entities "^1.0.2" + repeat-string "^1.5.4" + state-toggle "^1.0.0" + trim "0.0.1" + trim-trailing-lines "^1.0.0" + unherit "^1.0.4" + unist-util-remove-position "^1.0.0" + vfile-location "^2.0.0" + xtend "^4.0.1" + remark-parse@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/remark-parse/-/remark-parse-5.0.0.tgz#4c077f9e499044d1d5c13f80d7a98cf7b9285d95" @@ -10035,6 +10152,10 @@ shebang-regex@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" +shelljs@0.3.x: + version "0.3.0" + resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.3.0.tgz#3596e6307a781544f591f37da618360f31db57b1" + shellwords@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" @@ -10522,6 +10643,10 @@ strip-indent@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-2.0.0.tgz#5ef8db295d01e6ed6cbf7aab96998d7822527b68" +strip-json-comments@1.0.x: + version "1.0.4" + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-1.0.4.tgz#1e15fbcac97d3ee99bf2d73b4c656b082bbafb91" + strip-json-comments@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" @@ -11099,6 +11224,17 @@ unified@^6.0.0: x-is-function "^1.0.4" x-is-string "^0.1.0" +unified@^6.1.2: + version "6.2.0" + resolved "https://registry.yarnpkg.com/unified/-/unified-6.2.0.tgz#7fbd630f719126d67d40c644b7e3f617035f6dba" + dependencies: + bail "^1.0.0" + extend "^3.0.0" + is-plain-obj "^1.1.0" + trough "^1.0.0" + vfile "^2.0.0" + x-is-string "^0.1.0" + union-value@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.0.tgz#5c71c34cb5bad5dcebe3ea0cd08207ba5aa1aea4"