From 4520e6473afe901005e7ac532317f4b4f1af9ead Mon Sep 17 00:00:00 2001 From: fusagiko / takayamaki <24884114+takayamaki@users.noreply.github.com> Date: Mon, 3 Apr 2023 10:31:39 +0900 Subject: [Proposal] Make able to write React in Typescript (#16210) Co-authored-by: berlysia Co-authored-by: fusagiko / takayamaki --- .eslintrc.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to '.eslintrc.js') diff --git a/.eslintrc.js b/.eslintrc.js index faed3c54a..e38fd14f3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -20,13 +20,14 @@ module.exports = { ATTACHMENT_HOST: false, }, - parser: '@babel/eslint-parser', + parser: '@typescript-eslint/parser', plugins: [ 'react', 'jsx-a11y', 'import', 'promise', + '@typescript-eslint', ], parserOptions: { @@ -41,14 +42,13 @@ module.exports = { presets: ['@babel/react', '@babel/env'], }, }, - + extends: [ + 'plugin:import/typescript', + ], settings: { react: { version: 'detect', }, - 'import/extensions': [ - '.js', '.jsx', - ], 'import/ignore': [ 'node_modules', '\\.(css|scss|json)$', @@ -56,7 +56,7 @@ module.exports = { 'import/resolver': { node: { paths: ['app/javascript'], - extensions: ['.js', '.jsx'], + extensions: ['.js', '.jsx', '.ts', '.tsx'], }, }, }, @@ -97,7 +97,8 @@ module.exports = { 'no-self-assign': 'off', 'no-trailing-spaces': 'warn', 'no-unused-expressions': 'error', - 'no-unused-vars': [ + 'no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': [ 'error', { vars: 'all', @@ -116,7 +117,7 @@ module.exports = { semi: 'error', 'valid-typeof': 'error', - 'react/jsx-filename-extension': ['error', { 'allow': 'as-needed' }], + 'react/jsx-filename-extension': ['error', { extensions: ['.jsx', 'tsx'] }], 'react/jsx-boolean-value': 'error', 'react/jsx-closing-bracket-location': ['error', 'line-aligned'], 'react/jsx-curly-spacing': 'error', @@ -192,6 +193,8 @@ module.exports = { { js: 'never', jsx: 'never', + ts: 'never', + tsx: 'never', }, ], 'import/newline-after-import': 'error', -- cgit From 373e4a8ff034f189597cfbf651450b906eb598b1 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Mon, 3 Apr 2023 06:41:10 -0400 Subject: Move ESLint configs to overrides (#24370) --- .eslintrc.js | 36 +++++++++++++++++++++++--- app/javascript/mastodon/performance.js | 2 +- app/javascript/mastodon/utils/notifications.js | 2 +- app/javascript/packs/public-path.js | 1 + package.json | 2 +- 5 files changed, 36 insertions(+), 7 deletions(-) (limited to '.eslintrc.js') diff --git a/.eslintrc.js b/.eslintrc.js index e38fd14f3..bbdfa7de2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,7 +13,6 @@ module.exports = { browser: true, node: true, es6: true, - jest: true, }, globals: { @@ -42,9 +41,7 @@ module.exports = { presets: ['@babel/react', '@babel/env'], }, }, - extends: [ - 'plugin:import/typescript', - ], + settings: { react: { version: 'detect', @@ -203,6 +200,7 @@ module.exports = { { devDependencies: [ 'config/webpack/**', + 'app/javascript/mastodon/performance.js', 'app/javascript/mastodon/test_setup.js', 'app/javascript/**/__tests__/**', ], @@ -238,5 +236,35 @@ module.exports = { sourceType: 'script', }, }, + { + files: [ + '**/*.ts', + '**/*.tsx', + ], + + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:react/recommended', + 'plugin:jsx-a11y/recommended', + 'plugin:import/recommended', + 'plugin:import/typescript', + 'plugin:promise/recommended', + ], + + rules: { + '@typescript-eslint/no-explicit-any': 'off', + }, + }, + { + files: [ + '**/__tests__/*.js', + '**/__tests__/*.jsx', + ], + + env: { + jest: true, + }, + }, ], }; diff --git a/app/javascript/mastodon/performance.js b/app/javascript/mastodon/performance.js index 2b7e1bda8..95cf962d6 100644 --- a/app/javascript/mastodon/performance.js +++ b/app/javascript/mastodon/performance.js @@ -12,7 +12,7 @@ if (process.env.NODE_ENV === 'development') { // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1331135 performance.setResourceTimingBufferSize(Infinity); } - // eslint-disable-next-line import/no-extraneous-dependencies + marky = require('marky'); // allows us to easily do e.g. ReactPerf.printWasted() while debugging //window.ReactPerf = require('react-addons-perf'); diff --git a/app/javascript/mastodon/utils/notifications.js b/app/javascript/mastodon/utils/notifications.js index 7634cac21..42623ac7c 100644 --- a/app/javascript/mastodon/utils/notifications.js +++ b/app/javascript/mastodon/utils/notifications.js @@ -3,7 +3,7 @@ const checkNotificationPromise = () => { try { - // eslint-disable-next-line promise/catch-or-return + // eslint-disable-next-line promise/valid-params, promise/catch-or-return Notification.requestPermission().then(); } catch(e) { return false; diff --git a/app/javascript/packs/public-path.js b/app/javascript/packs/public-path.js index 539e3b8c4..f4d166a77 100644 --- a/app/javascript/packs/public-path.js +++ b/app/javascript/packs/public-path.js @@ -17,4 +17,5 @@ function formatPublicPath(host = '', path = '') { const cdnHost = document.querySelector('meta[name=cdn-host]'); +// eslint-disable-next-line no-undef __webpack_public_path__ = formatPublicPath(cdnHost ? cdnHost.content : '', process.env.PUBLIC_OUTPUT_PATH); diff --git a/package.json b/package.json index 9d798636d..0b06353a1 100644 --- a/package.json +++ b/package.json @@ -211,7 +211,7 @@ }, "lint-staged": { "*": "prettier --ignore-unknown --write", - "*.{js,jsx}": "eslint --fix", + "*.{js,jsx,ts,tsx}": "eslint --fix", "*.{css,scss}": "stylelint --fix" } } -- cgit