Skip to content

Commit 2f21f7e

Browse files
authored
docs/fix: flat config (#135)
1 parent 709f86f commit 2f21f7e

File tree

1 file changed

+79
-4
lines changed

1 file changed

+79
-4
lines changed

README.md

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,15 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
107107
npm install eslint-plugin-import-x --save-dev
108108
```
109109

110-
All rules are off by default. However, you may configure them manually
111-
in your `.eslintrc.(yml|json|js)`, or extend one of the canned configs:
110+
## Configuration (legacy: `.eslintrc*`)
111+
112+
> [!TIP]
113+
> If your eslint is `>=8.23.0`, you're 100% ready to use the new config system.
114+
> See dedicated section below.
115+
116+
> [!NOTE]
117+
> All rules are off by default. However, you may configure them manually
118+
> in your `.eslintrc.(yml|json|js)`, or extend one of the canned configs:
112119
113120
```yaml
114121
---
@@ -132,11 +139,12 @@ rules:
132139
# etc...
133140
```
134141

135-
## TypeScript
142+
### TypeScript
136143

137144
You may use the following snippet or assemble your own config using the granular settings described below it.
138145

139-
Make sure you have installed [`@typescript-eslint/parser`] and [`eslint-import-resolver-typescript`] which are used in the following configuration.
146+
> [!WARNING]
147+
> Make sure you have installed [`@typescript-eslint/parser`] and [`eslint-import-resolver-typescript`] which are used in the following configuration.
140148
141149
```yaml
142150
extends:
@@ -155,6 +163,73 @@ settings:
155163
[`@typescript-eslint/parser`]: https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser
156164
[`eslint-import-resolver-typescript`]: https://github.com/import-js/eslint-import-resolver-typescript
157165

166+
## Configuration (new: `eslint.config.js`)
167+
168+
From [`v8.21.0`](https://github.com/eslint/eslint/releases/tag/v8.21.0), ESLint announced a new config system.
169+
In the new system, `.eslintrc*` is no longer used. `eslint.config.js` would be the default config file name.
170+
171+
<details>
172+
<summary>JS example</summary>
173+
174+
```js
175+
import js from '@eslint/js'
176+
import eslintPluginImportX from 'eslint-plugin-import-x'
177+
178+
export default [
179+
js.configs.recommended,
180+
eslintPluginImportX.flatConfigs.recommended,
181+
]
182+
```
183+
184+
</details>
185+
186+
<details>
187+
<summary>Typescript example</summary>
188+
189+
You have to install `eslint-import-resolver-typescript`:
190+
191+
```shell
192+
npm install eslint-import-resolver-typescript --save-dev
193+
```
194+
195+
```js
196+
import js from '@eslint/js'
197+
import eslintPluginImportX from 'eslint-plugin-import-x'
198+
import tsParser from '@typescript-eslint/parser'
199+
200+
export default [
201+
js.configs.recommended,
202+
eslintPluginImportX.flatConfigs.recommended,
203+
eslintPluginImportX.flatConfigs.typescript,
204+
{
205+
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
206+
languageOptions: {
207+
parser: tsParser,
208+
ecmaVersion: 'latest',
209+
sourceType: 'module',
210+
},
211+
ignores: ['eslint.config.js'],
212+
rules: {
213+
'no-unused-vars': 'off',
214+
'import/no-dynamic-require': 'warn',
215+
'import/no-nodejs-modules': 'warn',
216+
},
217+
settings: {
218+
'import-x/resolver': {
219+
typescript: true,
220+
},
221+
},
222+
},
223+
]
224+
```
225+
226+
</details>
227+
228+
---
229+
230+
> [!NOTE]
231+
> A complete list of available configuration can be found in [config/flat folders](src/config/flat)
232+
158233
## Resolvers
159234

160235
With the advent of module bundlers and the current state of modules and module

0 commit comments

Comments
 (0)