-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Feature Request] Support new ESLint flat config #2556
Comments
If there's a way to support both configs at the same time, a PR would be appreciated. Look to jsx-eslint/eslint-plugin-jsx-a11y#891 and jsx-eslint/eslint-plugin-react#3429 for some preferred direction. |
Yup, my fork does support both configs. The only thing I'm unsure about in my fork is how to adapt the But based on this comment though, it sounds like maybe it's fine for the new config format not to set |
As long as the rules and configs work in both config systems, we're good. |
We're experiencing this issue as well. @TomerAberbach it would be really cool if you could submit a PR with your fixes! |
Thanks for the message! Been a bit busy with other stuff and kind of forgot about this 😅 I'll try to pick this up soon! |
I'll test this on my fork of @TomerAberbach's fork when I get a chance. |
Thanks @goosewobbler! A little while ago I tried making it so that all the tests get run twice (once with the legacy and once with the new config system), but got stuck trying to get stuff working and then got busy 🙃 Would be awesome if you're able to figure out how to test both systems! Happy to answer any questions about the fork if that would help as well |
I managed to make it work without changes in So that can pass the This is my working test config on node and typescript env. (EDIT: I just remove from using FlatCompat and directly construct the config) import importPlugin from "eslint-plugin-import";
export default [
// ... "eslint:recommended"
{
// All eslint-plugin-import config is here
languageOptions: {
parserOptions: {
// Eslint doesn't supply ecmaVersion in `parser.js` `context.parserOptions`
// This is required to avoid ecmaVersion < 2015 error or 'import' / 'export' error
ecmaVersion: "latest",
sourceType: "module",
},
},
plugins: { import: importPlugin },
settings: {
// This will do the trick
"import/parsers": {
espree: [".js", ".cjs", ".mjs", ".jsx"],
},
"import/resolver": {
typescript: true,
node: true,
},
},
rules: {
...importPlugin.configs["recommended"].rules,
},
},
// ... add other plugins like typescript-eslint etc
{
// All my custom config
languageOptions: {
// This default get replaced by plugins, so I added back. Not related probably.
ecmaVersion: "latest",
sourceType: "module",
// ... globals etc
},
},
// ... custom rules etc
] It was discovered and tested on a module
|
Any way to make it work in meantime with flat config? UPD.
|
Hello, I'm still having problems with mixing this plugin with my ESLint flat config. The fork mentioned in the OP seems to be a bit old. Is there any way I can use this plugin with the new flat config?
Thanks in advance. |
Not until that support is released. |
Downgraded ESLint config file to use the old cascading config instead of the new flat config. This allows eslint-plugin-import to be used, as it seems to only support the old config. See: - import-js/eslint-plugin-import#2556 - eslint/eslint#13481
Downgraded ESLint config file to use the old cascading config instead of the new flat config. This allows eslint-plugin-import to be used, as it seems to only support the old config. See: - import-js/eslint-plugin-import#2556 - eslint/eslint#13481
I guess my issue is related to this one but I'm not sure: I've recently migrated my import js from '@eslint/js'
/* eslint-disable import/no-unresolved */
import tsParser from '@typescript-eslint/parser'
import tsPlugin from '@typescript-eslint/eslint-plugin'
/* eslint-enable import/no-unresolved */
import prettierConfig from 'eslint-config-prettier'
import importPlugin from 'eslint-plugin-import'
import globals from 'globals'
export default [
{
ignores: ['.homeybuild/'],
},
js.configs.recommended,
{
languageOptions: {
ecmaVersion: 'latest',
globals: {
...globals.browser,
...globals.es2024,
...globals.node,
},
sourceType: 'module',
},
linterOptions: {
reportUnusedDisableDirectives: true,
},
plugins: {
import: importPlugin,
},
rules: importPlugin.configs.recommended.rules,
},
{
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'],
languageOptions: {
parser: tsParser,
parserOptions: {
project: './tsconfig.json',
},
},
plugins: {
'@typescript-eslint': tsPlugin,
},
rules: {
...tsPlugin.configs['eslint-recommended'].overrides[0].rules,
...tsPlugin.configs['strict-type-checked'].rules,
...tsPlugin.configs['stylistic-type-checked'].rules,
...importPlugin.configs.typescript.rules,
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
varsIgnorePattern: 'onHomeyReady',
},
],
},
settings: {
...importPlugin.configs.typescript.settings,
'import/resolver': {
...importPlugin.configs.typescript.settings['import/resolver'],
typescript: {
alwaysTryTypes: true,
},
},
},
},
prettierConfig,
] and I got the following errors:
Should it be solved with #2829, or is it another issue? I'm also wondering why I'm getting this error (only for
|
@OlivierZal yes, i suspect #2829 will solve your issue. For the other one, are those packages installed on disk and in package.json? |
Thanks @ljharb for your answer. Yes, they are installed and work very well: So do you think it is worth raising a separate issue on this one? |
Yes, I think so, thanks |
Running into the same error here I'll keep an eye on #2829 for sure 👍 |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
I was able to make it work on my setup following this official guide. A summary of the fix: import { fixupPluginRules } from '@eslint/compat'
import eslintPluginImport from 'eslint-plugin-import'
export default [
{
// code omit
plugins: { import: fixupPluginRules(eslintPluginImport) }
}
] |
I gave this a try. It doesn't seem to work with rules like I'm getting the error |
@glitch452 I tested the import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat'
import { FlatCompat } from '@eslint/eslintrc'
import js from '@eslint/js'
import tsParser from '@typescript-eslint/parser'
import eslintPluginImport from 'eslint-plugin-import'
import prettier from 'eslint-plugin-prettier'
import simpleImportSort from 'eslint-plugin-simple-import-sort'
import globals from 'globals'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})
export default [
...fixupConfigRules(
compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:jsx-a11y/recommended',
'plugin:prettier/recommended',
'plugin:storybook/recommended',
'plugin:jsonc/recommended-with-jsonc',
),
),
{
plugins: {
import: fixupPluginRules(eslintPluginImport),
'simple-import-sort': simpleImportSort,
prettier: fixupPluginRules(prettier),
},
languageOptions: {
globals: {
...globals.browser,
...globals.amd,
...globals.node,
},
parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
settings: {
react: {
version: 'detect',
},
'import/resolver': {
typescript: true,
node: {
paths: ['src'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
rules: {
// omit other rules
'import/export': 'error',
'import/newline-after-import': ['error', { count: 1, considerComments: true }],
},
},
] if I run the ESLint in this code: export const foo = function () {
/*...*/
} // Multiple exports of name 'foo'.
function bar() {
/*...*/
}
export { bar as foo } // Multiple exports of name 'foo'. I get |
This change adds support for ESLint's new Flat config system. It maintains backwards compatibility with eslintrc style configs as well. To achieve this, we're now dynamically creating flat configs on a new `flatConfigs` export. I was a bit on the fence about using this convention, or the other convention that's become prevalent in the community: adding the flat configs directly to the `configs` object, but with a 'flat/' prefix. I like this better, since it's slightly more ergonomic when using it in practice. e.g. `...importX.flatConfigs.recommended` vs `...importX.configs['flat/recommended']`, but i'm open to changing that. Example Usage ```js import importPlugin from 'eslint-plugin-import'; import js from '@eslint/js'; import tsParser from '@typescript-eslint/parser'; export default [ js.configs.recommended, importPlugin.flatConfigs.recommended, importPlugin.flatConfigs.react, importPlugin.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: in order to fill a gap in a future API gap for the `no-unused-module`, this takes advantage of a *proposed* new API on the ESLint context, that currently only exists in a POC state (unreleased). Closes import-js#2556
By using Sample code is as follows: import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
import { FlatCompat } from "@eslint/eslintrc";
import eslintPluginImport from "eslint-plugin-import";
import importRecommendedConfig from "eslint-plugin-import/config/recommended.js";
const flatCompat = new FlatCompat();
export default [
...fixupConfigRules(flatCompat.config(importRecommendedConfig)),
{
plugins: {
import: fixupPluginRules(eslintPluginImport),
},
rules: {
// some rewrite rules
},
settings: {
// some rewrite settings
},
},
]; By writing as above, can migrate import-related configurations to flat config without waiting for eslint-plugin-import to support flat config. That code related to imports including other configurations is in my repository. |
One more example: import importPlugin from 'eslint-plugin-import';
import importRecommented from 'eslint-plugin-import/config/recommended.js';
import { fixupPluginRules } from '@eslint/compat';
export default [
{
languageOptions: {
// import plugin does not use ecmaVersion and sourceType from languageOptions object
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
},
plugins: {
import: fixupPluginRules(importPlugin),
},
settings: {
'import/parsers': {
espree: ['.js', '.cjs', '.mjs'],
'@typescript-eslint/parser': ['.ts'],
},
'import/resolver': {
node: true,
typescript: true,
},
},
rules: {
...importRecommented.rules,
'import/no-named-as-default-member': 'off',
// Custom rules
},
},
]; |
This change adds support for ESLint's new Flat config system. It maintains backwards compatibility with eslintrc style configs as well. To achieve this, we're now dynamically creating flat configs on a new `flatConfigs` export. I was a bit on the fence about using this convention, or the other convention that's become prevalent in the community: adding the flat configs directly to the `configs` object, but with a 'flat/' prefix. I like this better, since it's slightly more ergonomic when using it in practice. e.g. `...importX.flatConfigs.recommended` vs `...importX.configs['flat/recommended']`, but i'm open to changing that. Example Usage ```js import importPlugin from 'eslint-plugin-import'; import js from '@eslint/js'; import tsParser from '@typescript-eslint/parser'; export default [ js.configs.recommended, importPlugin.flatConfigs.recommended, importPlugin.flatConfigs.react, importPlugin.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: in order to fill a gap in a future API gap for the `no-unused-module`, this takes advantage of a *proposed* new API on the ESLint context, that currently only exists in a POC state (unreleased). Closes import-js#2556
This change adds support for ESLint's new Flat config system. It maintains backwards compatibility with eslintrc style configs as well. To achieve this, we're now dynamically creating flat configs on a new `flatConfigs` export. I was a bit on the fence about using this convention, or the other convention that's become prevalent in the community: adding the flat configs directly to the `configs` object, but with a 'flat/' prefix. I like this better, since it's slightly more ergonomic when using it in practice. e.g. `...importX.flatConfigs.recommended` vs `...importX.configs['flat/recommended']`, but i'm open to changing that. Example Usage ```js import importPlugin from 'eslint-plugin-import'; import js from '@eslint/js'; import tsParser from '@typescript-eslint/parser'; export default [ js.configs.recommended, importPlugin.flatConfigs.recommended, importPlugin.flatConfigs.react, importPlugin.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: in order to fill a gap in a future API gap for the `no-unused-module`, this takes advantage of a *proposed* new API on the ESLint context, that currently only exists in a POC state (unreleased). Closes import-js#2556
This change adds support for ESLint's new Flat config system. It maintains backwards compatibility with eslintrc style configs as well. To achieve this, we're now dynamically creating flat configs on a new `flatConfigs` export. I was a bit on the fence about using this convention, or the other convention that's become prevalent in the community: adding the flat configs directly to the `configs` object, but with a 'flat/' prefix. I like this better, since it's slightly more ergonomic when using it in practice. e.g. `...importX.flatConfigs.recommended` vs `...importX.configs['flat/recommended']`, but i'm open to changing that. Example Usage ```js import importPlugin from 'eslint-plugin-import'; import js from '@eslint/js'; import tsParser from '@typescript-eslint/parser'; export default [ js.configs.recommended, importPlugin.flatConfigs.recommended, importPlugin.flatConfigs.react, importPlugin.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: in order to fill a gap in a future API gap for the `no-unused-module`, this takes advantage of a *proposed* new API on the ESLint context, that currently only exists in a POC state (unreleased). Closes import-js#2556
A release for this would be wonderful! |
Strong work! 💖 Loving reminder to update the package.json's dependencies as well - package managers still report an unmet peer for eslint@9 with version 2.30.0 |
@kfsass that's intentional; flat config works in eslint 8 and we don't yet support eslint 9. |
See import-js/eslint-plugin-import#2995 and import-js/eslint-plugin-import#2556#issuecomment-2121423498
* Remove `comma-dangle` * Begin ESLint v9 rewrite, remove unused React config * Switch to flat config * Change `no-console` to `warn` * Update package versions * Update peer dependencies versions, move import to dependencies * Mark as RC * Disable `import/no-named-as-default` See import-js/eslint-plugin-import#2995 and import-js/eslint-plugin-import#2556#issuecomment-2121423498 * Remove `plugins` * Update `eslint-plugin-import` In hindsight, I should have read the release notes and saw that the PR wasn't released yet even though it was merged. * Add typings * Release version 2.0.0 * Add the types to `package.json` * Add the ESLint configuration to the README
- breaking: `@stylistic/eslint-plugin` rules migration following this guide https://eslint.style/guide/migration - remove dependency `eslint-config-standard`, all rules imported (replace deprecated rules) - bump `eslint-plugin-import` and restore rule 'import/export' ref import-js/eslint-plugin-import#2556 - disable rule 'import/no-webpack-loader-syntax' - edit rules for 'generator-star-spacing' and 'yield-star-spacing'
- breaking: `@stylistic/eslint-plugin` rules migration following this guide https://eslint.style/guide/migration - remove dependency `eslint-config-standard`, all rules imported (replace deprecated rules) - bump `eslint-plugin-import` and restore rule 'import/export' ref import-js/eslint-plugin-import#2556 - disable rule 'import/no-webpack-loader-syntax' - edit rules for 'generator-star-spacing' and 'yield-star-spacing'
- breaking: `@stylistic/eslint-plugin` rules migration following this guide https://eslint.style/guide/migration - remove dependency `eslint-config-standard`, all rules imported (with deprecated rules replacing) - bump `eslint-plugin-import` and restore rule 'import/export' ref import-js/eslint-plugin-import#2556 new / changed rules - disable 'import/no-webpack-loader-syntax' (imported webmail rules) - add 'no-restricted-globals' to forbid using global event (imported webmail rules) - change 'generator-star-spacing' and 'yield-star-spacing' to always 'after'
- breaking: `@stylistic/eslint-plugin` rules migration following this guide https://eslint.style/guide/migration - remove dependency `eslint-config-standard`, all rules imported (with deprecated rules replacing) - bump `eslint-plugin-import` and restore rule 'import/export' ref import-js/eslint-plugin-import#2556 new / changed rules - disable 'import/no-webpack-loader-syntax' (imported webmail rules) - add 'no-restricted-globals' to forbid using global event (imported webmail rules) - change 'generator-star-spacing' and 'yield-star-spacing' to always 'after'
ESLint has a new experimental config file format and this plugin doesn't work with it. The plugin fails at this line because the new config format doesn't pass parsers via paths. Instead the parser object itself is passed.
I was able to mostly fix this in my fork, but because the
parserPath
doesn't exist anymore for this config format some of thekeysFromParser
logic won't work anymore.Anyway, figured I'd open this issue to start discussion on the new config file format!
The text was updated successfully, but these errors were encountered: