forked from import-js/eslint-plugin-import
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add flat config presets (#122)
Co-authored-by: Sukka <[email protected]>
- Loading branch information
1 parent
f37dc29
commit cd52e86
Showing
14 changed files
with
253 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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
@SukkaW No flatConfigs exports in v4.0.0
https://www.npmjs.com/package/eslint-plugin-import-x?activeTab=code