Skip to content

Commit dfbd06a

Browse files
committed
docs: update eslint flag config usage
1 parent cb48487 commit dfbd06a

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

README.md

+84
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,90 @@ yarn add -D eslint-plugin-import eslint-import-resolver-typescript
6262

6363
## Configuration
6464

65+
### `eslint.config.js`
66+
67+
If you are using `eslint-plugin-import-x@>=4.5.0`, you can use import/require to reference `eslint-import-resolver-typescript` directly in your ESLint flat config:
68+
69+
```js
70+
// eslint.config.js
71+
const {
72+
createTypeScriptImportResolver,
73+
} = require('eslint-import-resolver-typescript')
74+
75+
module.exports = [{
76+
settings: {
77+
"import/resolver-next": [
78+
createTypeScriptImportResolver({
79+
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
80+
81+
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json by default
82+
83+
// use <root>/path/to/folder/tsconfig.json
84+
project: "path/to/folder",
85+
86+
// Multiple tsconfigs (Useful for monorepos)
87+
88+
// use a glob pattern
89+
project: "packages/*/tsconfig.json",
90+
91+
// use an array
92+
project: [
93+
"packages/module-a/tsconfig.json",
94+
"packages/module-b/tsconfig.json"
95+
],
96+
97+
// use an array of glob patterns
98+
project: [
99+
"packages/*/tsconfig.json",
100+
"other-packages/*/tsconfig.json"
101+
]
102+
}),
103+
];
104+
}
105+
}]
106+
```
107+
108+
But if you are using `eslint-plugin-import` or the older version of `eslint-plugin-import-x`, you can't use require/import:
109+
110+
```js
111+
// eslint.config.js
112+
module.exports = [
113+
{
114+
settings: {
115+
'import/resolvers': {
116+
typescript: {
117+
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
118+
119+
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json by default
120+
121+
// use <root>/path/to/folder/tsconfig.json
122+
project: 'path/to/folder',
123+
124+
// Multiple tsconfigs (Useful for monorepos)
125+
126+
// use a glob pattern
127+
project: 'packages/*/tsconfig.json',
128+
129+
// use an array
130+
project: [
131+
'packages/module-a/tsconfig.json',
132+
'packages/module-b/tsconfig.json',
133+
],
134+
135+
// use an array of glob patterns
136+
project: [
137+
'packages/*/tsconfig.json',
138+
'other-packages/*/tsconfig.json',
139+
],
140+
},
141+
},
142+
},
143+
},
144+
]
145+
```
146+
147+
### `.eslintrc`
148+
65149
Add the following to your `.eslintrc` config:
66150

67151
```jsonc

0 commit comments

Comments
 (0)