Skip to content

Commit 62fedc5

Browse files
authored
docs: reorder eslintrc and eslint.config.* examples (#331)
1 parent 281cef3 commit 62fedc5

File tree

1 file changed

+53
-57
lines changed

1 file changed

+53
-57
lines changed

README.md

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ It started as a fork of [`eslint-plugin-import`] using [`get-tsconfig`] to repla
2525
- [Why](#why)
2626
- [Differences](#differences)
2727
- [Installation](#installation)
28-
- [Configuration (legacy: `.eslintrc*`)](#configuration-legacy-eslintrc)
29-
- [TypeScript](#typescript)
30-
- [Configuration (new: `eslint.config.js`)](#configuration-new-eslintconfigjs)
28+
- [Configuration (new: `eslint.config.*`)](#configuration-new-eslintconfig)
3129
- [JS example](#js-example)
3230
- [Typescript example](#typescript-example)
31+
- [Configuration (legacy: `.eslintrc*`)](#configuration-legacy-eslintrc)
32+
- [TypeScript](#typescript)
3333
- [Rules](#rules)
3434
- [Helpful warnings](#helpful-warnings)
3535
- [Module systems](#module-systems)
@@ -90,18 +90,66 @@ The list could be longer in the future, but we don't want to make it too long he
9090
npm install eslint-plugin-import-x --save-dev
9191
```
9292

93+
## Configuration (new: `eslint.config.*`)
94+
95+
From [`v8.21.0`](https://github.com/eslint/eslint/releases/tag/v8.21.0), ESLint announced a new config system.
96+
In the new system, `.eslintrc*` is no longer used. `eslint.config.*` would be the default config file name.
97+
98+
### JS example
99+
100+
```js
101+
import js from '@eslint/js'
102+
import * as importX from 'eslint-plugin-import-x'
103+
104+
export default [js.configs.recommended, importX.flatConfigs.recommended]
105+
```
106+
107+
### Typescript example
108+
109+
You have to install `eslint-import-resolver-typescript`:
110+
111+
```sh
112+
npm install eslint-import-resolver-typescript --save-dev
113+
```
114+
115+
```js
116+
import js from '@eslint/js'
117+
import * as importX from 'eslint-plugin-import-x'
118+
import tsParser from '@typescript-eslint/parser'
119+
120+
export default [
121+
js.configs.recommended,
122+
importX.flatConfigs.recommended,
123+
importX.flatConfigs.typescript,
124+
{
125+
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
126+
languageOptions: {
127+
parser: tsParser,
128+
ecmaVersion: 'latest',
129+
sourceType: 'module',
130+
},
131+
rules: {
132+
'import-x/no-dynamic-require': 'warn',
133+
'import-x/no-nodejs-modules': 'warn',
134+
},
135+
},
136+
]
137+
```
138+
139+
> [!NOTE]
140+
> A complete list of available configuration can be found in [config/flat folders](src/config/flat)
141+
93142
## Configuration (legacy: `.eslintrc*`)
94143

95144
> [!TIP]
96145
> If your eslint is `>=8.23.0`, you're 100% ready to use the new config system.
97-
> See dedicated section below.
146+
> See dedicated section above.
98147
99148
> [!NOTE]
100149
> All rules are off by default. However, you may configure them manually
101150
> in your `.eslintrc.(yml|json|js)`, or extend one of the canned configs:
102151
103152
```yaml
104-
---
105153
extends:
106154
- eslint:recommended
107155
- plugin:import-x/recommended
@@ -140,60 +188,8 @@ settings:
140188
# You will also need to install and configure the TypeScript resolver
141189
# See also https://github.com/import-js/eslint-import-resolver-typescript#configuration
142190
typescript: true
143-
node: true
144-
```
145-
146-
## Configuration (new: `eslint.config.js`)
147-
148-
From [`v8.21.0`](https://github.com/eslint/eslint/releases/tag/v8.21.0), ESLint announced a new config system.
149-
In the new system, `.eslintrc*` is no longer used. `eslint.config.js` would be the default config file name.
150-
151-
### JS example
152-
153-
```js
154-
import js from '@eslint/js'
155-
import * as pluginImportX from 'eslint-plugin-import-x'
156-
157-
export default [js.configs.recommended, pluginImportX.flatConfigs.recommended]
158191
```
159192
160-
### Typescript example
161-
162-
You have to install `eslint-import-resolver-typescript`:
163-
164-
```shell
165-
npm install eslint-import-resolver-typescript --save-dev
166-
```
167-
168-
```js
169-
import js from '@eslint/js'
170-
import * as pluginImportX from 'eslint-plugin-import-x'
171-
import tsParser from '@typescript-eslint/parser'
172-
173-
export default [
174-
js.configs.recommended,
175-
pluginImportX.flatConfigs.recommended,
176-
pluginImportX.flatConfigs.typescript,
177-
{
178-
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
179-
ignores: ['eslint.config.js'],
180-
languageOptions: {
181-
parser: tsParser,
182-
ecmaVersion: 'latest',
183-
sourceType: 'module',
184-
},
185-
rules: {
186-
'no-unused-vars': 'off',
187-
'import-x/no-dynamic-require': 'warn',
188-
'import-x/no-nodejs-modules': 'warn',
189-
},
190-
},
191-
]
192-
```
193-
194-
> [!NOTE]
195-
> A complete list of available configuration can be found in [config/flat folders](src/config/flat)
196-
197193
## Rules
198194
199195
<!-- begin auto-generated rules list -->

0 commit comments

Comments
 (0)