From 2d766100a52f9f72de63a5133692dd88e0f01b22 Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Sun, 26 Jan 2020 15:05:51 +0700 Subject: [PATCH 01/18] Update package.json --- packages/eslint-config-react-app/package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/eslint-config-react-app/package.json b/packages/eslint-config-react-app/package.json index 8ba2c6eb386..f32d179612a 100644 --- a/packages/eslint-config-react-app/package.json +++ b/packages/eslint-config-react-app/package.json @@ -15,8 +15,6 @@ "index.js" ], "peerDependencies": { - "@typescript-eslint/eslint-plugin": "2.x", - "@typescript-eslint/parser": "2.x", "babel-eslint": "10.x", "eslint": "6.x", "eslint-plugin-flowtype": "3.x", From ae88aaf44e13ddb6ec1c95ceffb3e05a8a766c5c Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Sun, 26 Jan 2020 15:23:07 +0700 Subject: [PATCH 02/18] Update index.js --- packages/eslint-config-react-app/index.js | 68 ++++++++++++----------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index 0d29e7995a6..9511100cb27 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -23,37 +23,12 @@ // To use them, explicitly reference them, e.g. `window.name` or `window.status`. const restrictedGlobals = require('confusing-browser-globals'); -module.exports = { - root: true, - - parser: 'babel-eslint', +const overrides = []; - plugins: ['import', 'flowtype', 'jsx-a11y', 'react', 'react-hooks'], - - env: { - browser: true, - commonjs: true, - es6: true, - jest: true, - node: true, - }, - - parserOptions: { - ecmaVersion: 2018, - sourceType: 'module', - ecmaFeatures: { - jsx: true, - }, - }, - - settings: { - react: { - version: 'detect', - }, - }, - - overrides: [ - { +// Lint tsx only if typescript is installed. +try { + require.resolve('typescript'); + overrides.push({ files: ['**/*.ts?(x)'], parser: '@typescript-eslint/parser', parserOptions: { @@ -111,8 +86,39 @@ module.exports = { 'no-useless-constructor': 'off', '@typescript-eslint/no-useless-constructor': 'warn', }, + }) +} catch {} + +module.exports = { + root: true, + + parser: 'babel-eslint', + + plugins: ['import', 'flowtype', 'jsx-a11y', 'react', 'react-hooks'], + + env: { + browser: true, + commonjs: true, + es6: true, + jest: true, + node: true, + }, + + parserOptions: { + ecmaVersion: 2018, + sourceType: 'module', + ecmaFeatures: { + jsx: true, + }, + }, + + settings: { + react: { + version: 'detect', }, - ], + }, + + overrides, // NOTE: When adding rules here, you need to make sure they are compatible with // `typescript-eslint`, as some rules such as `no-array-constructor` aren't compatible. From 9a3b8036c85f2485c466b9520d1aeeb22b9e9e11 Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Sun, 26 Jan 2020 15:23:35 +0700 Subject: [PATCH 03/18] Update README.md --- packages/eslint-config-react-app/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-react-app/README.md b/packages/eslint-config-react-app/README.md index 4ada3431245..d1cbdd95cce 100644 --- a/packages/eslint-config-react-app/README.md +++ b/packages/eslint-config-react-app/README.md @@ -19,7 +19,7 @@ If you want to use this ESLint configuration in a project not built with Create First, install this package, ESLint and the necessary plugins. ```sh -npm install --save-dev eslint-config-react-app @typescript-eslint/eslint-plugin@2.x @typescript-eslint/parser@2.x babel-eslint@10.x eslint@6.x eslint-plugin-flowtype@3.x eslint-plugin-import@2.x eslint-plugin-jsx-a11y@6.x eslint-plugin-react@7.x eslint-plugin-react-hooks@1.x +npm install --save-dev eslint-config-react-app babel-eslint@10.x eslint@6.x eslint-plugin-flowtype@3.x eslint-plugin-import@2.x eslint-plugin-jsx-a11y@6.x eslint-plugin-react@7.x eslint-plugin-react-hooks@1.x ``` Then create a file named `.eslintrc.json` with following contents in the root folder of your project: From b1199ce48e42d1fe8e4d8b734cd09128e80ee7a0 Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Sun, 26 Jan 2020 15:29:05 +0700 Subject: [PATCH 04/18] Update package.json --- packages/react-scripts/package.json | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index fd47d222ca2..18ddf171240 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -30,8 +30,6 @@ "dependencies": { "@babel/core": "7.7.5", "@svgr/webpack": "4.3.3", - "@typescript-eslint/eslint-plugin": "^2.10.0", - "@typescript-eslint/parser": "^2.10.0", "babel-eslint": "10.0.3", "babel-jest": "^24.9.0", "babel-loader": "8.0.6", @@ -89,11 +87,19 @@ "fsevents": "2.1.2" }, "peerDependencies": { - "typescript": "^3.2.1" + "typescript": "^3.2.1", + "@typescript-eslint/eslint-plugin": "^2.10.0", + "@typescript-eslint/parser": "^2.10.0" }, "peerDependenciesMeta": { "typescript": { "optional": true + }, + "@typescript-eslint/eslint-plugin": { + "optional": true + }, + "@typescript-eslint/parser": { + "optional": true } }, "browserslist": { From e70e356a36f682e963d0161308d4d17415d0ac69 Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Sun, 26 Jan 2020 15:33:21 +0700 Subject: [PATCH 05/18] Update package.json --- packages/eslint-config-react-app/package.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/eslint-config-react-app/package.json b/packages/eslint-config-react-app/package.json index f32d179612a..7e20cd8639a 100644 --- a/packages/eslint-config-react-app/package.json +++ b/packages/eslint-config-react-app/package.json @@ -15,6 +15,8 @@ "index.js" ], "peerDependencies": { + "@typescript-eslint/eslint-plugin": "2.x", + "@typescript-eslint/parser": "2.x", "babel-eslint": "10.x", "eslint": "6.x", "eslint-plugin-flowtype": "3.x", @@ -23,6 +25,14 @@ "eslint-plugin-react": "7.x", "eslint-plugin-react-hooks": "1.x" }, + "peerDependenciesMeta": { + "@typescript-eslint/eslint-plugin": { + "optional": true + }, + "@typescript-eslint/parser": { + "optional": true + } + }, "dependencies": { "confusing-browser-globals": "^1.0.9" } From cef45d52b80b979b0415d1d2fef9ff09fc9e3fc5 Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Sun, 26 Jan 2020 15:53:25 +0700 Subject: [PATCH 06/18] Update adding-typescript.md --- docusaurus/docs/adding-typescript.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docusaurus/docs/adding-typescript.md b/docusaurus/docs/adding-typescript.md index 40c9c2242a8..057372dce05 100644 --- a/docusaurus/docs/adding-typescript.md +++ b/docusaurus/docs/adding-typescript.md @@ -26,11 +26,11 @@ yarn create react-app my-app --template typescript To add [TypeScript](https://www.typescriptlang.org/) to a Create React App project, first install it: ```sh -npm install --save typescript @types/node @types/react @types/react-dom @types/jest +npm install --save typescript @typescript-eslint/eslint-plugin @typescript-eslint/parser @types/node @types/react @types/react-dom @types/jest # or -yarn add typescript @types/node @types/react @types/react-dom @types/jest +yarn add typescript @typescript-eslint/eslint-plugin @typescript-eslint/parser @types/node @types/react @types/react-dom @types/jest ``` Next, rename any file to be a TypeScript file (e.g. `src/index.js` to `src/index.tsx`) and **restart your development server**! From c419c87742a5157501914479c9d169d27dbc33f3 Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Sun, 26 Jan 2020 16:01:02 +0700 Subject: [PATCH 07/18] Update template.json --- packages/cra-template-typescript/template.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/cra-template-typescript/template.json b/packages/cra-template-typescript/template.json index 1bb882699f6..9eedcedda80 100644 --- a/packages/cra-template-typescript/template.json +++ b/packages/cra-template-typescript/template.json @@ -8,7 +8,9 @@ "@types/react": "^16.9.0", "@types/react-dom": "^16.9.0", "@types/jest": "^24.0.0", - "typescript": "~3.7.2" + "typescript": "~3.7.2", + "@typescript-eslint/eslint-plugin": "^2.10.0", + "@typescript-eslint/parser": "^2.10.0" } } } From 90ac7e93fcda9fcd8d70853bbdf916b8fd7d1043 Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Fri, 17 Apr 2020 10:36:38 +0700 Subject: [PATCH 08/18] Update index.js --- packages/eslint-config-react-app/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index 9511100cb27..5eb9b5d3cdc 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -87,7 +87,7 @@ try { '@typescript-eslint/no-useless-constructor': 'warn', }, }) -} catch {} +} module.exports = { root: true, From 63762d4d69fe032881b5bd6d02d19585ebcef5ee Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Fri, 17 Apr 2020 10:45:21 +0700 Subject: [PATCH 09/18] Update index.js --- packages/eslint-config-react-app/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index 5eb9b5d3cdc..76f9dfbb5b4 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -87,6 +87,8 @@ try { '@typescript-eslint/no-useless-constructor': 'warn', }, }) +} catch(e) { + if (e.code !== 'MODULE_NOT_FOUND') throw e; } module.exports = { From 142a3eff6fec8d05f16929f2f08ab38694dbe836 Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Fri, 17 Apr 2020 10:48:36 +0700 Subject: [PATCH 10/18] Update index.js --- packages/eslint-config-react-app/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index 76f9dfbb5b4..367e04863a6 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -88,7 +88,9 @@ try { }, }) } catch(e) { - if (e.code !== 'MODULE_NOT_FOUND') throw e; + if (e.code !== 'MODULE_NOT_FOUND') { + throw e; + } } module.exports = { From 6a67beeffce0a6fd859ff23b97a9846b2db6ee59 Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Fri, 17 Apr 2020 11:07:44 +0700 Subject: [PATCH 11/18] Update package.json --- packages/react-scripts/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 8261df06a39..146970749c8 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -90,8 +90,8 @@ }, "peerDependencies": { "typescript": "^3.2.1", - "@typescript-eslint/eslint-plugin": "^2.10.0", - "@typescript-eslint/parser": "^2.10.0" + "@typescript-eslint/eslint-plugin": "^2.28.0", + "@typescript-eslint/parser": "^2.28.0" }, "peerDependenciesMeta": { "typescript": { From 7cf291ab0518d9668e9457648799fba766770b45 Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Fri, 17 Apr 2020 11:08:18 +0700 Subject: [PATCH 12/18] Update template.json --- packages/cra-template-typescript/template.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cra-template-typescript/template.json b/packages/cra-template-typescript/template.json index d96e71e1aee..5da99d184d9 100644 --- a/packages/cra-template-typescript/template.json +++ b/packages/cra-template-typescript/template.json @@ -9,8 +9,8 @@ "@types/react-dom": "^16.9.0", "@types/jest": "^24.0.0", "typescript": "^3.8.0", - "@typescript-eslint/eslint-plugin": "^2.10.0", - "@typescript-eslint/parser": "^2.10.0" + "@typescript-eslint/eslint-plugin": "^2.28.0", + "@typescript-eslint/parser": "^2.28.0" } } } From 9124f7d688b242145af18663578e92c0ce7da109 Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Fri, 17 Apr 2020 11:30:51 +0700 Subject: [PATCH 13/18] Update index.js --- packages/eslint-config-react-app/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index 367e04863a6..618385202c3 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -27,7 +27,7 @@ const overrides = []; // Lint tsx only if typescript is installed. try { - require.resolve('typescript'); + require.resolve('@typescript-eslint/eslint-plugin'); overrides.push({ files: ['**/*.ts?(x)'], parser: '@typescript-eslint/parser', From f005ab0802630a7ddc67e3395f3dacea555ec4cb Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Fri, 17 Apr 2020 12:11:55 +0700 Subject: [PATCH 14/18] Update package.json --- packages/eslint-config-react-app/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-react-app/package.json b/packages/eslint-config-react-app/package.json index d5c6275cb41..e106f10f1f8 100644 --- a/packages/eslint-config-react-app/package.json +++ b/packages/eslint-config-react-app/package.json @@ -34,6 +34,7 @@ } }, "dependencies": { - "confusing-browser-globals": "^1.0.9" + "confusing-browser-globals": "^1.0.9", + "resolve": "^1.16.0" } } From 1ea335ca69b7c7ee8371512a04f4eeabbb58aa8f Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Fri, 17 Apr 2020 12:13:25 +0700 Subject: [PATCH 15/18] Update index.js --- packages/eslint-config-react-app/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index 618385202c3..f1967ff4c0f 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -23,11 +23,13 @@ // To use them, explicitly reference them, e.g. `window.name` or `window.status`. const restrictedGlobals = require('confusing-browser-globals'); +const resolve = require('resolve'); + const overrides = []; // Lint tsx only if typescript is installed. try { - require.resolve('@typescript-eslint/eslint-plugin'); + resolve.sync('typescript'); overrides.push({ files: ['**/*.ts?(x)'], parser: '@typescript-eslint/parser', From 3ab8e44f22cc2ec51d5edc8454cbb7a294cd001d Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Fri, 17 Apr 2020 12:37:28 +0700 Subject: [PATCH 16/18] Update index.js --- packages/eslint-config-react-app/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index f1967ff4c0f..de5aab8c010 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -29,7 +29,9 @@ const overrides = []; // Lint tsx only if typescript is installed. try { - resolve.sync('typescript'); + resolve.sync('typescript', { + basedir: process.cwd() + }); overrides.push({ files: ['**/*.ts?(x)'], parser: '@typescript-eslint/parser', From c46e10491b8d8ea7354e12375eee1d141adc516e Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Fri, 17 Apr 2020 13:09:38 +0700 Subject: [PATCH 17/18] Update index.js --- packages/eslint-config-react-app/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index de5aab8c010..1039883f926 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -24,13 +24,15 @@ const restrictedGlobals = require('confusing-browser-globals'); const resolve = require('resolve'); +const path = require('path'); +const fs = require('fs'); const overrides = []; // Lint tsx only if typescript is installed. try { resolve.sync('typescript', { - basedir: process.cwd() + basedir: path.resolve(fs.realpathSync(process.cwd()), 'node_modules'); }); overrides.push({ files: ['**/*.ts?(x)'], From 6fc60b75f8f501c6c4abef2503e823716ec8d3e0 Mon Sep 17 00:00:00 2001 From: Thew Dhanat <26767607+ThewBear@users.noreply.github.com> Date: Fri, 17 Apr 2020 13:17:10 +0700 Subject: [PATCH 18/18] Update index.js --- packages/eslint-config-react-app/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index 1039883f926..37497420251 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -32,7 +32,7 @@ const overrides = []; // Lint tsx only if typescript is installed. try { resolve.sync('typescript', { - basedir: path.resolve(fs.realpathSync(process.cwd()), 'node_modules'); + basedir: path.resolve(fs.realpathSync(process.cwd()), 'node_modules') }); overrides.push({ files: ['**/*.ts?(x)'],