From fb2d88edc04244fb6f11711bb9e3e3501484a609 Mon Sep 17 00:00:00 2001 From: Andrei Dumitrescu <5057797+andreidmt@users.noreply.github.com> Date: Wed, 20 Jan 2021 20:18:18 +0100 Subject: [PATCH] feat: Add React with Typescript target --- rules/import-ts.js | 8 --- rules/react.js | 16 ------ targets/node-ts.js | 2 + targets/react-ts.js | 133 ++++++++++++++++++++++++++++++++++++++++++++ targets/react.js | 30 ++++++++++ 5 files changed, 165 insertions(+), 24 deletions(-) create mode 100644 targets/react-ts.js diff --git a/rules/import-ts.js b/rules/import-ts.js index b6d35ef..b2b3432 100644 --- a/rules/import-ts.js +++ b/rules/import-ts.js @@ -2,12 +2,6 @@ module.exports = { rules: { - /* - * A list of file extensions that will be parsed as modules and - * inspected for exports. - */ - "import/extensions": ["error", "always", { js: "never", ts: "never" }], - /* * TypeScript compilation already ensures that named imports exist in the * referenced module @@ -16,8 +10,6 @@ module.exports = { }, settings: { - "import/extensions": [".ts", ".tsx", ".d.ts", ".js", ".jsx"], - "import/external-module-folders": ["node_modules", "node_modules/@types"], "import/parsers": { diff --git a/rules/react.js b/rules/react.js index ddf8a90..4bd9948 100644 --- a/rules/react.js +++ b/rules/react.js @@ -65,9 +65,6 @@ module.exports = { }, ], - // Restrict file extensions that may contain JSX - "react/jsx-filename-extension": "error", - // Validate JSX maximum depth "react/jsx-max-depth": "off", @@ -335,18 +332,5 @@ module.exports = { // Prevent usage of button elements without an explicit type attribute "react/button-has-type": "error", - - /* - * A list of file extensions that will be parsed as modules and - * inspected for exports. - */ - "import/extensions": [ - "error", - "always", - { - js: "never", - jsx: "never", - }, - ], }, } diff --git a/targets/node-ts.js b/targets/node-ts.js index 3f92df3..9d585ac 100644 --- a/targets/node-ts.js +++ b/targets/node-ts.js @@ -43,6 +43,8 @@ module.exports = { plugins: ["json", "no-inferred-method-name"], + ignorePatterns: ["dist/*.js", "*.d.ts"], + rules: { "@typescript-eslint/no-var-requires": "off", diff --git a/targets/react-ts.js b/targets/react-ts.js new file mode 100644 index 0000000..300e36f --- /dev/null +++ b/targets/react-ts.js @@ -0,0 +1,133 @@ +/* eslint-env node */ + +module.exports = { + parserOptions: { + ecmaVersion: 2020, + sourceType: "module", + ecmaFeatures: { + jsx: true, + }, + }, + + env: { + browser: true, + es6: true, + node: false, + }, + + extends: [ + ...[ + "../rules/best.practices", + "../rules/comments", + "../rules/errors", + "../rules/es6", + "../rules/html", + "../rules/import", + "../rules/import-ts", + "../rules/jsdoc", + "../rules/promise", + "../rules/react", + "../rules/style", + "../rules/unicorn", + "../rules/variables", + "../rules/prettier", + ].map(require.resolve), + + // Disable ESLint rules from @typescript-eslint/eslint-plugin that + // conflict with prettier + "prettier/@typescript-eslint", + + "plugin:@typescript-eslint/recommended", + ], + + plugins: ["json", "no-inferred-method-name"], + + ignorePatterns: ["dist/*.js", "*.d.ts"], + + rules: { + "react/prop-types": "off", + + // Ensure JSDoc comments are valid + "valid-jsdoc": [ + "error", + { + requireReturn: false, + requireReturnDescription: false, + requireReturnType: true, + }, + ], + + "@typescript-eslint/no-var-requires": "off", + + // Disable, it gives false positives. let eslint/no-unused-vars + "@typescript-eslint/no-unused-vars": "off", + + // Restrict file extensions that may contain JSX + "react/jsx-filename-extension": [ + "error", + { extensions: [".js", ".jsx", ".tsx", ".ts"] }, + ], + + // Let Typescript handle it + "@typescript-eslint/no-use-before-define": "error", + "no-use-before-define": "off", + + /* + * A list of file extensions that will be parsed as modules and + * inspected for exports. + */ + "import/extensions": [ + "error", + "always", + { + js: "never", + ts: "never", + jsx: "never", + tsx: "never", + }, + ], + + "no-unused-vars": [ + "error", + { + args: "after-used", + varsIgnorePattern: "debug", + }, + ], + }, + + settings: { + react: { + version: "detect", + }, + + /* + * A list of regex strings that, if matched by a path, will not report + * the matching module if no exports are found. + */ + "import/ignore": [".(sass|scss|less|css)$"], + + /* + * A list of file extensions that will be parsed as modules and + * inspected for exports. + */ + "import/extensions": [ + "error", + "always", + { + js: "never", + ts: "never", + jsx: "never", + tsx: "never", + }, + ], + + "no-unused-vars": [ + "error", + { + args: "after-used", + varsIgnorePattern: "debug", + }, + ], + }, +} diff --git a/targets/react.js b/targets/react.js index 6192250..c93297c 100644 --- a/targets/react.js +++ b/targets/react.js @@ -37,7 +37,37 @@ module.exports = { plugins: ["json", "no-inferred-method-name"], + rules: { + "no-unused-vars": [ + "error", + { + args: "after-used", + varsIgnorePattern: "debug", + }, + ], + + /* + * A list of file extensions that will be parsed as modules and + * inspected for exports. + */ + "import/extensions": [ + "error", + "always", + { + js: "never", + jsx: "never", + }, + ], + + // Restrict file extensions that may contain JSX + "react/jsx-filename-extension": ["error", { extensions: [".js", ".jsx"] }], + }, + settings: { + react: { + version: "detect", + }, + /* * A list of regex strings that, if matched by a path, will not report * the matching module if no exports are found.