From 81c3ca6e9b36b691585bf36f4fbd79dd9cee0fa3 Mon Sep 17 00:00:00 2001 From: Marco Pasqualetti Date: Tue, 27 Aug 2024 18:51:00 +0200 Subject: [PATCH 1/2] docs: add flat config configuration --- README.md | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1d7c5a4fe..2361952d2 100644 --- a/README.md +++ b/README.md @@ -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 --- @@ -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: @@ -155,6 +163,62 @@ 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. + +
+ JS example + +```js +import js from '@eslint/js' +import eslintPluginImportX from 'eslint-plugin-import-x' + +export default [ + js.configs.recommended, + eslintPluginImportX.flatConfigs.recommended, +] +``` + +
+ +
+ Typescript example + +```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', + }, + }, +] +``` + +
+ +--- + +> [!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 From c7dae5be61f50a9e9741f5d9ee274cb334b33cb5 Mon Sep 17 00:00:00 2001 From: Marco Pasqualetti Date: Sat, 31 Aug 2024 04:00:44 +0200 Subject: [PATCH 2/2] docs(flat configuration): add settings with ts resolver --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 2361952d2..03c417031 100644 --- a/README.md +++ b/README.md @@ -186,6 +186,12 @@ export default [
Typescript example +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' @@ -208,6 +214,11 @@ export default [ 'import/no-dynamic-require': 'warn', 'import/no-nodejs-modules': 'warn', }, + settings: { + 'import-x/resolver': { + typescript: true, + }, + }, }, ] ```