nuxt / eslint

Collection of ESLint-related packages for Nuxt
https://eslint.nuxt.com
MIT License
515 stars 65 forks source link

ConfigError: Key "plugins": Cannot redefine plugin "import" in Nuxt ESLint configuration #435

Closed RomanKollerSnoop closed 1 month ago

RomanKollerSnoop commented 1 month ago

Environment

Package

@nuxt/eslint

Reproduction

// eslint.config.js


import * as espree from 'espree'
import { FlatCompat } from '@eslint/eslintrc'
import path from 'path'
import { fileURLToPath } from 'url'
import js from '@eslint/js'
import gitignore from 'eslint-config-flat-gitignore'
import withNuxt from './.nuxt/eslint.config.mjs'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

const compat = new FlatCompat({
    baseDirectory: __dirname,
    resolvePluginsRelativeTo: __dirname,
    recommendedConfig: js.configs.recommended,

})

export default withNuxt(
    gitignore({
        files: [
            '.gitignore',
        ],
    }),
    {
        files: [ 'api/bin/www', 'bin/cli' ],
        languageOptions: {
            parser: espree,
        },
    },
    ...compat.config({
        extends: [ 'airbnb-base', 'plugin:vue/vue3-strongly-recommended' ],

        rules: {
            '@typescript-eslint/member-delimiter-style': [ 'error', {
                multiline: {
                    delimiter: 'none',
                    requireLast: true,
                },
                singleline: {
                    delimiter: 'semi',
                    requireLast: false,
                },
            } ],
            'quote-props': 'off',
            'indent': [ 2, 4, { 'SwitchCase': 1 } ],
            '@stylistic/indent': [ 2, 4, { 'SwitchCase': 1 } ],
            'semi': [ 'error', 'never' ],
            'space-before-function-paren': [ 'error', 'always' ],
            'array-bracket-spacing': [ 'error', 'always', { singleValue: false } ],
            'arrow-parens': [ 'error', 'as-needed', { requireForBlockBody: true } ],
            '@stylistic/array-bracket-spacing': [ 'error', 'always', { singleValue: false } ],
            '@stylistic/arrow-parens': [ 'error', 'as-needed', { requireForBlockBody: true } ],
            '@stylistic/semi': [ 'error', 'never' ],
            '@stylistic/space-before-function-paren': [ 'error', 'always' ],
            '@stylistic/quote-props': 'off',
            'global-require': 'off',
            'import/extensions': 'off',
            'import/newline-after-import': [ 'error', { count: 2 } ],
            'import/no-unresolved': 'off',
            'import/prefer-default-export': 'off',
            'import/no-named-as-default-member': 'off',
            'import/no-extraneous-dependencies': 'off',
            'import/no-named-as-default': 'off',
            'max-len': 'off',
            'no-empty': 'off',
            'no-magic-numbers': 'off',
            'no-multi-spaces': [ 'error', { ignoreEOLComments: true } ],
            'no-multiple-empty-lines': [ 'error', { max: 2 } ],
            '@stylistic/no-multi-spaces': [ 'error', { ignoreEOLComments: true } ],
            '@stylistic/no-multiple-empty-lines': [ 'error', { max: 2 } ],
            'no-param-reassign': 'error',
            'no-underscore-dangle': 'off',
            'no-unused-vars': [ 'error', { args: 'after-used', ignoreRestSiblings: false, vars: 'all' } ],
            'object-curly-newline': [ 'error', {
                ExportDeclaration: { minProperties: 3, multiline: true },
                ImportDeclaration: { consistent: true },
                ObjectExpression: { consistent: true },
                ObjectPattern: { consistent: true },
            } ],
            '@stylistic/object-curly-newline': [ 'error', {
                ExportDeclaration: { minProperties: 3, multiline: true },
                ImportDeclaration: { consistent: true },
                ObjectExpression: { consistent: true },
                ObjectPattern: { consistent: true },
            } ],

            'prefer-promise-reject-errors': 'off',
            'vue/array-bracket-spacing': [ 'error', 'always', { singleValue: false } ],
            'vue/html-indent': [ 'error', 4 ],
            'vue/multi-word-component-names': 0,
            'vue/no-v-model-argument': 'off',
            'vue/object-curly-spacing': [ 'error', 'always' ],
            'vue/singleline-html-element-content-newline': 0,

            // New rules
            'vue/script-indent': [ 'error', 4, { 'baseIndent': 0 } ],
            'brace-style': [ 'error', '1tbs', { 'allowSingleLine': true } ],
            '@stylistic/brace-style': [ 'error', '1tbs', { 'allowSingleLine': true } ],
            'no-nested-ternary': 'off',
            'import/no-dynamic-require': 'off',
            'vue/require-default-prop': 'off',
            'no-console': 'off',
            // Temp rules
            'vue/valid-v-for': 'off',
        },
        overrides: [
            {
                'files': ['*.vue'],
                'rules': {
                    'indent': 'off',
                    '@stylistic/indent': 'off',
                    'no-unused-vars': 'off',
                    '@typescript-eslint/no-unused-vars': 'off',
                    '@stylistic/indent-binary-ops': 'off',
                },
            },
        ],
    }),
)

Describe the bug

I am using ESLint version 9.2.0 in a Nuxt 3 project. When running ESLint, it throws a ConfigError indicating that the "import" plugin is being redefined. This issue occurs even after following the recommended setup and ensuring that the plugin is not explicitly defined multiple times in my configuration.

This started happening after updating the nuxt eslint module.

Additional context

No response

Logs

ConfigError: Config (unnamed): Key "plugins": Cannot redefine plugin "import".
    at rethrowConfigError (/path/to/project/node_modules/@humanwhocodes/config-array/api.js:230:8)
    at /path/to/project/node_modules/@humanwhocodes/config-array/api.js:1032:5
    at Array.reduce (<anonymous>)
    at FlatConfigArray.getConfig (/path/to/project/node_modules/@humanwhocodes/config-array/api.js:1028:39)
    at FlatConfigArray.isFileIgnored (/path/to/project/node_modules/@humanwhocodes/config-array/api.js:1060:15)
    at /path/to/project/node_modules/eslint/lib/eslint/eslint-helpers.js:548:38
    at Array.forEach (<anonymous>)
    at findFiles (/path/to/project/node_modules/eslint/lib/eslint/eslint-helpers.js:537:11)
    at async ESLint.lintFiles (/path/to/project/node_modules/eslint/lib/eslint/eslint.js:847:27)
    at async Object.execute (/path/to/project/node_modules/eslint/lib/cli.js:500:23)
antfu commented 1 month ago

We temporarily closed this due to the lack of enough information. We could not identify whether it was a bug or a userland misconfiguration with the given info. Please provide a minimal reproduction to reopen the issue. Thanks.

Why reproduction is required

RomanKollerSnoop commented 1 month ago

We temporarily closed this due to the lack of enough information. We could not identify whether it was a bug or a userland misconfiguration with the given info. Please provide a minimal reproduction to reopen the issue. Thanks.

Why reproduction is required

Well... the reproduction is there. Just copy the configs and paste them into the eslint.config.js file in any nuxt 3 project :/