Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add flat config configuration #135

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 79 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,15 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
npm install eslint-plugin-import-x --save-dev
```

All rules are off by default. However, you may configure them manually
in your `.eslintrc.(yml|json|js)`, or extend one of the canned configs:
## Configuration (legacy: `.eslintrc*`)

> [!TIP]
> If your eslint is `>=8.23.0`, you're 100% ready to use the new config system.
> See dedicated section below.

> [!NOTE]
> All rules are off by default. However, you may configure them manually
> in your `.eslintrc.(yml|json|js)`, or extend one of the canned configs:

```yaml
---
Expand All @@ -132,11 +139,12 @@ rules:
# etc...
```

## TypeScript
### TypeScript

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

Make sure you have installed [`@typescript-eslint/parser`] and [`eslint-import-resolver-typescript`] which are used in the following configuration.
> [!WARNING]
> Make sure you have installed [`@typescript-eslint/parser`] and [`eslint-import-resolver-typescript`] which are used in the following configuration.

```yaml
extends:
Expand All @@ -155,6 +163,73 @@ settings:
[`@typescript-eslint/parser`]: https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser
[`eslint-import-resolver-typescript`]: https://github.com/import-js/eslint-import-resolver-typescript

## Configuration (new: `eslint.config.js`)

From [`v8.21.0`](https://github.com/eslint/eslint/releases/tag/v8.21.0), ESLint announced a new config system.
In the new system, `.eslintrc*` is no longer used. `eslint.config.js` would be the default config file name.

<details>
<summary>JS example</summary>

```js
import js from '@eslint/js'
import eslintPluginImportX from 'eslint-plugin-import-x'

export default [
js.configs.recommended,
eslintPluginImportX.flatConfigs.recommended,
]
```

</details>

<details>
<summary>Typescript example</summary>

You have to install `eslint-import-resolver-typescript`:

```shell
npm install eslint-import-resolver-typescript --save-dev
```

```js
import js from '@eslint/js'
import eslintPluginImportX from 'eslint-plugin-import-x'
import tsParser from '@typescript-eslint/parser'

export default [
js.configs.recommended,
eslintPluginImportX.flatConfigs.recommended,
eslintPluginImportX.flatConfigs.typescript,
{
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
languageOptions: {
parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'module',
},
ignores: ['eslint.config.js'],
rules: {
'no-unused-vars': 'off',
'import/no-dynamic-require': 'warn',
'import/no-nodejs-modules': 'warn',
},
settings: {
'import-x/resolver': {
typescript: true,
},
},
},
]
```

</details>

---

> [!NOTE]
> A complete list of available configuration can be found in [config/flat folders](src/config/flat)

## Resolvers

With the advent of module bundlers and the current state of modules and module
Expand Down
Loading