Skip to content

Commit

Permalink
feat(eslint-config): support import resolutions out of the box
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepolischuk committed Feb 27, 2024
1 parent 82dc55d commit 6eac94e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
28 changes: 1 addition & 27 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
7 changes: 7 additions & 0 deletions packages/eslint-config/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ module.exports = {
}
}
],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
}
}
},
ignorePatterns: [
'.git/',
'node_modules/',
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions packages/eslint-config/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,12 @@ module.exports = {
extends: ['plugin:@typescript-eslint/disable-type-checked']
}
],
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true
}
}
},
ignorePatterns: ['*.d.ts']
}

0 comments on commit 6eac94e

Please sign in to comment.