-
-
Notifications
You must be signed in to change notification settings - Fork 57
feat: add flat config support #122
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| "eslint-plugin-import-x": minor | ||
| --- | ||
|
|
||
| Add ESLint flat configuration presets. You can access them with: | ||
|
|
||
| ```ts | ||
| import eslintPluginImportX from 'eslint-plugin-import-x'; | ||
|
|
||
| eslintPluginImportX.flatConfigs.recommended; | ||
| eslintPluginImportX.flatConfigs.react; | ||
| eslintPluginImportX.flatConfigs.typescript; | ||
| eslintPluginImportX.flatConfigs.electron; | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import type { PluginFlatConfig } from '../../types' | ||
|
|
||
| /** | ||
| * Default settings for Electron applications. | ||
| */ | ||
| export default { | ||
| settings: { | ||
| 'import-x/core-modules': ['electron'], | ||
| }, | ||
| } satisfies PluginFlatConfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type { PluginFlatConfig } from '../../types' | ||
|
|
||
| /** | ||
| * unopinionated config. just the things that are necessarily runtime errors | ||
| * waiting to happen. | ||
| */ | ||
| export default { | ||
| rules: { | ||
| 'import-x/no-unresolved': 2, | ||
| 'import-x/named': 2, | ||
| 'import-x/namespace': 2, | ||
| 'import-x/default': 2, | ||
| 'import-x/export': 2, | ||
| }, | ||
| } satisfies PluginFlatConfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type { PluginFlatBaseConfig } from '../../types' | ||
|
|
||
| /** | ||
| * adds platform extensions to Node resolver | ||
| */ | ||
| export default { | ||
| settings: { | ||
| 'import-x/resolver': { | ||
| node: { | ||
| // Note: will not complain if only _one_ of these files exists. | ||
| extensions: ['.js', '.web.js', '.ios.js', '.android.js'], | ||
| }, | ||
| }, | ||
| }, | ||
| } satisfies PluginFlatBaseConfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import type { PluginFlatBaseConfig } from '../../types' | ||
|
|
||
| /** | ||
| * Adds `.jsx` as an extension, and enables JSX parsing. | ||
| * | ||
| * Even if _you_ aren't using JSX (or .jsx) directly, if your dependencies | ||
| * define jsnext:main and have JSX internally, you may run into problems | ||
| * if you don't enable these settings at the top level. | ||
| */ | ||
| export default { | ||
| settings: { | ||
| 'import-x/extensions': ['.js', '.jsx', '.mjs', '.cjs'], | ||
| }, | ||
| languageOptions: { | ||
| parserOptions: { | ||
| ecmaFeatures: { | ||
| jsx: true, | ||
| }, | ||
| }, | ||
| }, | ||
| } satisfies PluginFlatBaseConfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import type { PluginFlatBaseConfig } from '../../types' | ||
|
|
||
| /** | ||
| * The basics. | ||
| */ | ||
| export default { | ||
| rules: { | ||
| // analysis/correctness | ||
| 'import-x/no-unresolved': 'error', | ||
| 'import-x/named': 'error', | ||
| 'import-x/namespace': 'error', | ||
| 'import-x/default': 'error', | ||
| 'import-x/export': 'error', | ||
|
|
||
| // red flags (thus, warnings) | ||
| 'import-x/no-named-as-default': 'warn', | ||
| 'import-x/no-named-as-default-member': 'warn', | ||
| 'import-x/no-duplicates': 'warn', | ||
| }, | ||
|
|
||
| // need all these for parsing dependencies (even if _your_ code doesn't need | ||
| // all of them) | ||
| languageOptions: { | ||
| ecmaVersion: 2018, | ||
| sourceType: 'module', | ||
| }, | ||
| } satisfies PluginFlatBaseConfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { PluginFlatBaseConfig } from '../../types' | ||
|
|
||
| /** | ||
| * Rules in progress. | ||
| * | ||
| * Do not expect these to adhere to semver across releases. | ||
| */ | ||
| export default { | ||
| rules: { | ||
| 'import-x/no-deprecated': 1, | ||
| }, | ||
| } satisfies PluginFlatBaseConfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { PluginFlatBaseConfig } from '../../types' | ||
|
|
||
| /** | ||
| * This config: | ||
| * 1) adds `.jsx`, `.ts`, `.cts`, `.mts`, and `.tsx` as an extension | ||
| * 2) enables JSX/TSX parsing | ||
| */ | ||
|
|
||
| // Omit `.d.ts` because 1) TypeScript compilation already confirms that | ||
| // types are resolved, and 2) it would mask an unresolved | ||
| // `.ts`/`.tsx`/`.js`/`.jsx` implementation. | ||
| const typeScriptExtensions = ['.ts', '.tsx', '.cts', '.mts'] as const | ||
|
|
||
| const allExtensions = [ | ||
| ...typeScriptExtensions, | ||
| '.js', | ||
| '.jsx', | ||
| '.cjs', | ||
| '.mjs', | ||
| ] as const | ||
|
|
||
| export default { | ||
| settings: { | ||
| 'import-x/extensions': allExtensions, | ||
| 'import-x/external-module-folders': ['node_modules', 'node_modules/@types'], | ||
| 'import-x/parsers': { | ||
| '@typescript-eslint/parser': [...typeScriptExtensions], | ||
| }, | ||
| 'import-x/resolver': { | ||
| node: { | ||
| extensions: allExtensions, | ||
| }, | ||
| }, | ||
| }, | ||
| rules: { | ||
| // analysis/correctness | ||
|
|
||
| // TypeScript compilation already ensures that named imports exist in the referenced module | ||
| 'import-x/named': 'off', | ||
| }, | ||
| } satisfies PluginFlatBaseConfig | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { PluginFlatBaseConfig } from '../../types' | ||
|
|
||
| /** | ||
| * more opinionated config. | ||
| */ | ||
| export default { | ||
| rules: { | ||
| 'import-x/no-named-as-default': 1, | ||
| 'import-x/no-named-as-default-member': 1, | ||
| 'import-x/no-duplicates': 1, | ||
| }, | ||
| } satisfies PluginFlatBaseConfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.