From ed6d4c6e5762f3c5aaa0cd0f503d8573a5b91f11 Mon Sep 17 00:00:00 2001 From: Kevin Barabash Date: Thu, 16 Feb 2023 10:46:16 -0500 Subject: [PATCH 1/4] FEI-4957.11: Reorganize eslint configs --- .eslintrc.js | 57 +++++++++++++++------------- packages/eslint-config-khan/index.js | 33 +++++++++++++--- 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 12fcb255..007755ce 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,24 +9,6 @@ module.exports = { "jsx-a11y": ["./*.js", "src/*.js"], }, }, - "import/parsers": { - "@typescript-eslint/parser": [".ts", ".tsx"], - }, - "import/resolver": { - typescript: { - project: [ - "packages/*/tsconfig.json", - "packages/tsconfig-shared.json", - ], - }, - node: { - project: [ - "packages/*/tsconfig.json", - "packages/tsconfig-shared.json", - ], - }, - }, - "import/extensions": [".js", ".jsx", ".ts", ".tsx"], }, globals: { __IS_BROWSER__: "readonly", @@ -64,14 +46,25 @@ module.exports = { }, ], rules: { + /** + * built-in rules + */ "new-cap": "off", "no-invalid-this": "off", "object-curly-spacing": "off", semi: "off", + + /** + * @babel rules + */ "@babel/new-cap": "error", "@babel/no-invalid-this": "error", "@babel/object-curly-spacing": "error", "@babel/semi": "error", + + /** + * import rules + */ "import/no-default-export": "error", "import/no-unresolved": "error", "import/named": "error", @@ -101,14 +94,6 @@ module.exports = { ignorePackages: true, }, ], - "jest/no-focused-tests": "error", - "promise/always-return": "error", - "promise/no-return-wrap": "error", - "promise/param-names": "error", - "promise/catch-or-return": "error", - "promise/no-new-statics": "error", - "promise/no-return-in-finally": "error", - "monorepo/no-internal-import": "error", // NOTE: This rule reports false positives for cross-module imports using // `@khanacademy/wonder-stuff-*`. This is likely due to a bad interaction // with the settings we're using for `import/resolver`. @@ -125,6 +110,24 @@ module.exports = { }, ], - "@typescript-eslint/no-explicit-any": "off", + /** + * jest rules + */ + "jest/no-focused-tests": "error", + + /** + * promise rules + */ + "promise/always-return": "error", + "promise/no-return-wrap": "error", + "promise/param-names": "error", + "promise/catch-or-return": "error", + "promise/no-new-statics": "error", + "promise/no-return-in-finally": "error", + + /** + * monorepo rules + */ + "monorepo/no-internal-import": "error", }, }; diff --git a/packages/eslint-config-khan/index.js b/packages/eslint-config-khan/index.js index bc50c721..6551a7bd 100644 --- a/packages/eslint-config-khan/index.js +++ b/packages/eslint-config-khan/index.js @@ -24,6 +24,24 @@ module.exports = { react: { version: "16.4", }, + "import/parsers": { + "@typescript-eslint/parser": [".ts", ".tsx"], + }, + "import/resolver": { + typescript: { + project: [ + "packages/*/tsconfig.json", + "packages/tsconfig-shared.json", + ], + }, + node: { + project: [ + "packages/*/tsconfig.json", + "packages/tsconfig-shared.json", + ], + }, + }, + "import/extensions": [".js", ".jsx", ".ts", ".tsx"], }, rules: { /** @@ -61,11 +79,7 @@ module.exports = { "no-unexpected-multiline": ERROR, "no-unreachable": ERROR, "no-unused-expressions": ERROR, - "no-unused-vars": OFF, - "@typescript-eslint/no-unused-vars": [ - ERROR, - {args: "none", varsIgnorePattern: "^_*$"}, - ], + "no-unused-vars": OFF, // Superseded by @typescript-eslint/no-unused-vars "no-useless-call": ERROR, "no-var": ERROR, "no-with": ERROR, @@ -121,5 +135,14 @@ module.exports = { "react/sort-prop-types": OFF, // We tried this, but there wasn't much benefit. "react/no-unsafe": WARN, "react/no-deprecated": WARN, + + /** + * typescript rules + */ + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-unused-vars": [ + ERROR, + {args: "none", varsIgnorePattern: "^_*$"}, + ], }, }; From 7c77c5448bc6f84f9cf1b057fbe117d1fea8b5bd Mon Sep 17 00:00:00 2001 From: Kevin Barabash Date: Thu, 16 Feb 2023 11:00:23 -0500 Subject: [PATCH 2/4] move import/resolver settings back into .eslintrc.js, add 'Quick Start' to eslint-config-khan's README.md --- .eslintrc.js | 14 ++++++++ packages/eslint-config-khan/README.md | 46 +++++++++++++++++++++++++++ packages/eslint-config-khan/index.js | 14 -------- 3 files changed, 60 insertions(+), 14 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 007755ce..00c29d76 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,6 +9,20 @@ module.exports = { "jsx-a11y": ["./*.js", "src/*.js"], }, }, + "import/resolver": { + typescript: { + project: [ + "packages/*/tsconfig.json", + "packages/tsconfig-shared.json", + ], + }, + node: { + project: [ + "packages/*/tsconfig.json", + "packages/tsconfig-shared.json", + ], + }, + }, }, globals: { __IS_BROWSER__: "readonly", diff --git a/packages/eslint-config-khan/README.md b/packages/eslint-config-khan/README.md index b2326edf..38178370 100644 --- a/packages/eslint-config-khan/README.md +++ b/packages/eslint-config-khan/README.md @@ -1,3 +1,49 @@ # eslint-config-khan Shared Khan Academy eslint configuration. + +## Quick Start + +- `yarn add @khanacademy/eslint-config` +- Update your .eslintrc.js file to: + - extend `"@khanacademy"` + - include settings for `"import/resolver"` + +For monorepos the `"import/resolver"` settings will look like this: + +``` + settings: { + "import/resolver": { + typescript: { + project: [ + "packages/*/tsconfig.json", + "packages/tsconfig-shared.json", + ], + }, + node: { + project: [ + "packages/*/tsconfig.json", + "packages/tsconfig-shared.json", + ], + }, + }, + }, +``` + +For regulard repos, the settings will look like this: + +``` +For monorepos the `"import/resolver"` settings will look like this: + +``` + settings: { + "import/resolver": { + typescript: { + project: "tsconfig.json", + }, + node: { + project: "tsconfig.json", + }, + }, + }, +``` diff --git a/packages/eslint-config-khan/index.js b/packages/eslint-config-khan/index.js index 6551a7bd..f916bb13 100644 --- a/packages/eslint-config-khan/index.js +++ b/packages/eslint-config-khan/index.js @@ -27,20 +27,6 @@ module.exports = { "import/parsers": { "@typescript-eslint/parser": [".ts", ".tsx"], }, - "import/resolver": { - typescript: { - project: [ - "packages/*/tsconfig.json", - "packages/tsconfig-shared.json", - ], - }, - node: { - project: [ - "packages/*/tsconfig.json", - "packages/tsconfig-shared.json", - ], - }, - }, "import/extensions": [".js", ".jsx", ".ts", ".tsx"], }, rules: { From 9ca8eb831e0267cc386801bc2dba2e9f187aa0cf Mon Sep 17 00:00:00 2001 From: Kevin Barabash Date: Thu, 16 Feb 2023 11:06:07 -0500 Subject: [PATCH 3/4] add missing peer deeps and remove unnecessary peer deps from eslint-config-khan's package.json --- packages/eslint-config-khan/package.json | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/eslint-config-khan/package.json b/packages/eslint-config-khan/package.json index a04a8d18..b88936cf 100644 --- a/packages/eslint-config-khan/package.json +++ b/packages/eslint-config-khan/package.json @@ -11,17 +11,14 @@ "license": "MIT", "dependencies": {}, "peerDependencies": { + "@typescript-eslint/eslint-plugin": "^5.52.0", + "@typescript-eslint/parser": "^5.52.0", "eslint": "^7.27.0", "eslint-config-prettier": "^8.3.0", - "eslint-plugin-babel": "^5.3.1", - "eslint-plugin-eslint-comments": "^3.2.0", - "eslint-plugin-graphql": "^4.0.0", "eslint-plugin-import": "^2.23.4", "eslint-plugin-jsx-a11y": "^6.4.1", "eslint-plugin-prettier": "^3.4.0", "eslint-plugin-react": "^7.24.0", - "eslint-plugin-react-hooks": "^4.2.0", - "eslint-plugin-react-native": "^3.11.0", - "eslint-plugin-react-native-animation-linter": "^0.1.2" + "eslint-import-resolver-typescript": "^3.5.3" } -} \ No newline at end of file +} From 5b9a7b745988512da6a9d1a00d36ea2095fd623d Mon Sep 17 00:00:00 2001 From: Kevin Barabash Date: Thu, 16 Feb 2023 11:15:56 -0500 Subject: [PATCH 4/4] add changeset file --- .changeset/long-hairs-turn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/long-hairs-turn.md diff --git a/.changeset/long-hairs-turn.md b/.changeset/long-hairs-turn.md new file mode 100644 index 00000000..9622e46a --- /dev/null +++ b/.changeset/long-hairs-turn.md @@ -0,0 +1,5 @@ +--- +"@khanacademy/eslint-config": patch +--- + +Add missing settings