From 6eac94efcb350b74b73c583423dfdf8708158ba9 Mon Sep 17 00:00:00 2001 From: Andrey Polischuk Date: Tue, 27 Feb 2024 11:27:24 +0300 Subject: [PATCH] feat(eslint-config): support import resolutions out of the box --- packages/eslint-config/README.md | 28 +--------------------------- packages/eslint-config/js.js | 7 +++++++ packages/eslint-config/package.json | 1 + packages/eslint-config/ts.js | 7 +++++++ 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/packages/eslint-config/README.md b/packages/eslint-config/README.md index fcc639e..9ae5ece 100644 --- a/packages/eslint-config/README.md +++ b/packages/eslint-config/README.md @@ -71,30 +71,4 @@ Example `.eslintrc.json` for TypeScript Next.js project: } ``` -Note that the `@rambler-tech/eslint-config/ts` should be second to last in the list since it includes `@typescript-eslint/parser`: - -## Module resolution - -Included [`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import) requires additional settings if you use custom module resolution. For example if you use aliases instead of long relative paths: - -```ts -import App from 'components/app' -``` - -This config includes [`eslint-import-resolver-webpack`](https://www.npmjs.com/package/eslint-import-resolver-webpack) and [`eslint-import-resolver-typescript`](https://www.npmjs.com/package/eslint-import-resolver-typescript). - -To use resolution options from `tsconfig.json` add the following settings to your `.eslintrc.json`. - -```json -{ - "extends": [ - "@rambler-tech/eslint-config", - "@rambler-tech/eslint-config/ts" - ], - "settings": { - "import/resolver": { - "typescript": true - } - } -} -``` +Note that the `@rambler-tech/eslint-config/ts` should be second to last in the list since it includes `@typescript-eslint/parser` diff --git a/packages/eslint-config/js.js b/packages/eslint-config/js.js index 0fc85e5..9711881 100644 --- a/packages/eslint-config/js.js +++ b/packages/eslint-config/js.js @@ -248,6 +248,13 @@ module.exports = { } } ], + settings: { + 'import/resolver': { + node: { + extensions: ['.js', '.jsx', '.ts', '.tsx'] + } + } + }, ignorePatterns: [ '.git/', 'node_modules/', diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index 0923f3a..d9e9ac1 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -15,6 +15,7 @@ "@typescript-eslint/parser": "^6.21.0", "eslint-config-next": "^14.1.0", "eslint-config-prettier": "^9.1.0", + "eslint-import-resolver-node": "^0.3.9", "eslint-import-resolver-typescript": "^3.6.1", "eslint-import-resolver-webpack": "^0.13.8", "eslint-plugin-import": "^2.29.1", diff --git a/packages/eslint-config/ts.js b/packages/eslint-config/ts.js index e02c61f..59ff9c8 100644 --- a/packages/eslint-config/ts.js +++ b/packages/eslint-config/ts.js @@ -65,5 +65,12 @@ module.exports = { extends: ['plugin:@typescript-eslint/disable-type-checked'] } ], + settings: { + 'import/resolver': { + typescript: { + alwaysTryTypes: true + } + } + }, ignorePatterns: ['*.d.ts'] }