From 4b543396a5db086a3223c9e1a6b69fbf47c58836 Mon Sep 17 00:00:00 2001 From: James Lefrere Date: Wed, 23 Dec 2020 14:16:28 +0100 Subject: [PATCH] Workaround for CRA issue - Add workaround for https://github.com/facebook/create-react-app/issues/9929 --- .eslintrc | 38 ------------------------------------- .eslintrc.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 54 insertions(+), 39 deletions(-) delete mode 100644 .eslintrc create mode 100644 .eslintrc.js diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 1d8ab6209..000000000 --- a/.eslintrc +++ /dev/null @@ -1,38 +0,0 @@ -{ - "extends": [ - "airbnb-typescript", - "airbnb/hooks", - "plugin:@typescript-eslint/recommended", - "prettier", - "prettier/react", - "prettier/@typescript-eslint" - ], - "env": { - "node": true, - "browser": true, - "jest": true - }, - "parserOptions": { - "project": "./tsconfig.json" - }, - "rules": { - "@typescript-eslint/explicit-function-return-type": [ - "error", - { "allowExpressions": true, "allowTypedFunctionExpressions": true } - ], - "@typescript-eslint/no-unused-vars": [ - "error", - { "varsIgnorePattern": "_" } - ], - "@typescript-eslint/ban-types": "off", - "@typescript-eslint/naming-convention": "off", - "arrow-body-style": "off", - "no-underscore-dangle": "off", - "no-console": ["error", { "allow": ["warn", "error"] }], - "react/no-unescaped-entities": "off", - "import/prefer-default-export": "off", - "import/no-default-export": "error", - "react/prop-types": "off", - "no-nested-ternary": "off" - } -} diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..b31cf957c --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,53 @@ +const realConfig = { + extends: [ + 'airbnb-typescript', + 'airbnb/hooks', + 'plugin:@typescript-eslint/recommended', + 'prettier', + 'prettier/react', + 'prettier/@typescript-eslint', + ], + env: { + node: true, + browser: true, + jest: true, + }, + parserOptions: { + project: './tsconfig.json', + }, + rules: { + '@typescript-eslint/explicit-function-return-type': [ + 'error', + { allowExpressions: true, allowTypedFunctionExpressions: true }, + ], + '@typescript-eslint/no-unused-vars': ['error', { varsIgnorePattern: '_' }], + '@typescript-eslint/ban-types': 'off', + '@typescript-eslint/naming-convention': 'off', + 'arrow-body-style': 'off', + 'no-underscore-dangle': 'off', + 'no-console': ['error', { allow: ['warn', 'error'] }], + 'react/no-unescaped-entities': 'off', + 'import/prefer-default-export': 'off', + 'import/no-default-export': 'error', + 'react/prop-types': 'off', + 'no-nested-ternary': 'off', + }, +}; + +const nopConfig = { + /* + + This config is meant to do nothing. + + It exists because there's no good way to disable ESLint in Create React App: + https://github.com/facebook/create-react-app/issues/9929 + + So the workaround here is to craft a config that does as little as possible, + and then conditionally use it. + + */ + + ignorePatterns: ['**/*.ts', '**/*.tsx', './*.js', 'config/*.js'], +}; + +module.exports = process.env.DISABLE_ESLINT ? nopConfig : realConfig; diff --git a/package.json b/package.json index 270513a90..cd0e1615b 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "eject": "react-scripts eject", "lint": "yarn eslint './src/**/*.{ts,tsx}' --fix", "provision": "sh ./scripts/provision.sh", - "start": "react-scripts start", + "start": "DISABLE_ESLINT=true react-scripts start", "test:ropsten": "env-cmd -f .env.example.ropsten react-scripts test", "test": "react-scripts test", "script": "yarn ts-node --project ./scripts/tsconfig.json ./scripts/run.ts",