From e149476cf8eaea5089833ba431e2b5180a0311ce Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 8 Jan 2023 00:26:33 -0800 Subject: [PATCH] Add Prettier to format TypeScript files (cherry picked from commit de56862bb97b092c5fc44359caf3b2abdbcfdf96) --- frontend/.eslintrc.js | 8 +++++++- frontend/.prettierignore | 10 ++++++++++ frontend/.prettierrc.json | 6 ++++++ frontend/.vscode/settings.json | 23 +++++++++++++++++++++-- package.json | 3 +++ yarn.lock | 29 +++++++++++++++++++++++++++++ 6 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 frontend/.prettierignore create mode 100644 frontend/.prettierrc.json diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js index 38c44f05e..603b20a48 100644 --- a/frontend/.eslintrc.js +++ b/frontend/.eslintrc.js @@ -49,7 +49,8 @@ module.exports = { 'react-hooks', 'simple-import-sort', 'import', - '@typescript-eslint' + '@typescript-eslint', + 'prettier' ], settings: { @@ -352,12 +353,17 @@ module.exports = { project: './tsconfig.json' }, + extends: [ + 'prettier' + ], + rules: Object.assign(typescriptEslintRecommended.rules, { 'no-shadow': 'off', // These should be enabled after cleaning things up '@typescript-eslint/no-unused-vars': 'warn', '@typescript-eslint/explicit-function-return-type': 'off', 'react/prop-types': 'off', + 'prettier/prettier': 'error', 'simple-import-sort/imports': [ 'error', { diff --git a/frontend/.prettierignore b/frontend/.prettierignore new file mode 100644 index 000000000..3e6367c54 --- /dev/null +++ b/frontend/.prettierignore @@ -0,0 +1,10 @@ +# Ignore everything recursively +* + +# But not the .ts files +!*.ts* + +*css.d.ts + +# Check subdirectories too +!*/ diff --git a/frontend/.prettierrc.json b/frontend/.prettierrc.json new file mode 100644 index 000000000..2f91ee691 --- /dev/null +++ b/frontend/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "arrowParens": "always", + "endOfLine": "auto", + "singleQuote": true, + "trailingComma": "es5" +} diff --git a/frontend/.vscode/settings.json b/frontend/.vscode/settings.json index 0fb2bf460..edb88e0e7 100644 --- a/frontend/.vscode/settings.json +++ b/frontend/.vscode/settings.json @@ -1,4 +1,23 @@ // Place your settings in this file to overwrite default and user settings. { - "files.insertFinalNewline": true -} \ No newline at end of file + "files.insertFinalNewline": true, + + "files.exclude": { + "**/node_modules": true, + "**/*.d.css": true + }, + + "editor.formatOnSave": false, + "editor.codeActionsOnSave": { + "source.fixAll": true + }, + + "typescript.preferences.quoteStyle": "single", + + "eslint.validate": [ + "javascript", + "javascriptreact", + "typescript", + "typescriptreact" + ], +} diff --git a/package.json b/package.json index f57460738..d93275c45 100644 --- a/package.json +++ b/package.json @@ -107,9 +107,11 @@ "css-loader": "6.7.3", "css-modules-typescript-loader": "4.0.1", "eslint": "8.40.0", + "eslint-config-prettier": "8.8.0", "eslint-plugin-filenames": "1.3.2", "eslint-plugin-import": "2.27.5", "eslint-plugin-json": "3.1.0", + "eslint-plugin-prettier": "4.2.1", "eslint-plugin-react": "7.32.2", "eslint-plugin-react-hooks": "4.6.0", "eslint-plugin-simple-import-sort": "10.0.0", @@ -126,6 +128,7 @@ "postcss-nested": "6.0.1", "postcss-simple-vars": "7.0.1", "postcss-url": "10.1.3", + "prettier": "2.8.8", "require-nocache": "1.0.0", "rimraf": "4.4.1", "run-sequence": "2.2.1", diff --git a/yarn.lock b/yarn.lock index 1ac349d45..36d3c0e2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2860,6 +2860,11 @@ escape-string-regexp@^4.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== +eslint-config-prettier@8.8.0: + version "8.8.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.8.0.tgz#bfda738d412adc917fd7b038857110efe98c9348" + integrity sha512-wLbQiFre3tdGgpDv67NQKnJuTlcUVYHas3k+DZCc2U2BadthoEY4B7hLPvAxaqdyOGCzuLfii2fqGph10va7oA== + eslint-import-resolver-node@^0.3.7: version "0.3.7" resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.7.tgz#83b375187d412324a1963d84fa664377a23eb4d7" @@ -2915,6 +2920,13 @@ eslint-plugin-json@3.1.0: lodash "^4.17.21" vscode-json-languageservice "^4.1.6" +eslint-plugin-prettier@4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-4.2.1.tgz#651cbb88b1dab98bfd42f017a12fa6b2d993f94b" + integrity sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ== + dependencies: + prettier-linter-helpers "^1.0.0" + eslint-plugin-react-hooks@4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz#4c3e697ad95b77e93f8646aaa1630c1ba607edd3" @@ -3093,6 +3105,11 @@ fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== +fast-diff@^1.1.2: + version "1.3.0" + resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.3.0.tgz#ece407fa550a64d638536cd727e129c61616e0f0" + integrity sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw== + fast-glob@^3.2.11, fast-glob@^3.2.12, fast-glob@^3.2.9: version "3.2.12" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.12.tgz#7f39ec99c2e6ab030337142da9e0c18f37afae80" @@ -4991,6 +5008,18 @@ prelude-ls@^1.2.1: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== +prettier-linter-helpers@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b" + integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w== + dependencies: + fast-diff "^1.1.2" + +prettier@2.8.8: + version "2.8.8" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da" + integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q== + pretty-error@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/pretty-error/-/pretty-error-4.0.0.tgz#90a703f46dd7234adb46d0f84823e9d1cb8f10d6"