From e35eca7a1c30ea81398a3434c6fe514cbc2a8fcc Mon Sep 17 00:00:00 2001 From: HD Date: Fri, 17 Jun 2022 00:30:05 +0800 Subject: [PATCH] feat: add eslint support for typescript files and fix no unused vars error when add support for TypeScript features (we must disable the base rule as it can report incorrect errors, use instead of @typescript-eslint/no-unused-vars) ref: https://github.com/typescript-eslint/typescript-eslint /blob/main/packages/eslint-plugin/docs/rules/no-unused-vars.md --- .eslintrc.json | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 1a1200ff..e44d3743 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,19 +1,21 @@ { "extends": ["eslint:recommended", "plugin:react/recommended", "prettier"], - "plugins": ["react-hooks"], + "plugins": ["import", "react", "react-hooks", "@typescript-eslint"], "rules": { + "@typescript-eslint/no-unused-vars": ["error", { "ignoreRestSiblings": true }], "react/jsx-uses-react": "off", "react/react-in-jsx-scope": "off", "semi": 2, "no-console": "off", "react/prop-types": 0, "react/no-unescaped-entities": "off", - "no-unused-vars": ["error", { "ignoreRestSiblings": true }], + "no-unused-vars": "off", "react-hooks/rules-of-hooks": "error", "react-hooks/exhaustive-deps": "warn", "max-lines": ["warn", { "max": 500 }], "react/display-name": 0 }, + "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2021, "sourceType": "module", @@ -32,7 +34,16 @@ }, "settings": { "react": { - "version": "17" + "version": "18" + }, + "import/extensions": [".js", ".jsx", ".ts", ".tsx"], + "import/parsers": { + "@typescript-eslint/parser": [".ts", ".tsx"] + }, + "import/resolver": { + "node": { + "extensions": [".js", ".jsx", ".ts", ".tsx"] + } } } }