Skip to content

ConfigError: Config (unnamed): Key "plugins": Cannot redefine plugin "depend". #43

@tbroyer

Description

@tbroyer

When used as follows, the plugin cannot be given the namespace depend:

import { defineConfig } from "eslint/config";
import * as depend from "eslint-plugin-depend";

export default defineConfig([
  {
    files: ["**/*.js"],
    plugins: {
      depend,
    },
    extends: ["depend/flat/recommended"],
  }
]);

It fails with:

Oops! Something went wrong! :(

ESLint: 9.23.0

ConfigError: Config (unnamed): Key "plugins": Cannot redefine plugin "depend".
    at rethrowConfigError (<redacted>/node_modules/@eslint/config-array/dist/cjs/index.cjs:328:8)
    at <redacted>/node_modules/@eslint/config-array/dist/cjs/index.cjs:1174:5
    at Array.reduce (<anonymous>)
    at FlatConfigArray.getConfigWithStatus (<redacted>/node_modules/@eslint/config-array/dist/cjs/index.cjs:1167:43)
    at FlatConfigArray.getConfig (<redacted>/node_modules/@eslint/config-array/dist/cjs/index.cjs:1196:15)
    at entryFilter (<redacted>/node_modules/eslint/lib/eslint/eslint-helpers.js:282:27)
    at async NodeHfs.<anonymous> (file://<redacted>/node_modules/@humanfs/core/src/hfs.js:574:24)
    at async NodeHfs.<anonymous> (file://<redacted>/node_modules/@humanfs/core/src/hfs.js:604:6)
    at async NodeHfs.walk (file://<redacted>/node_modules/@humanfs/core/src/hfs.js:614:3)
    at async globSearch (<redacted>/node_modules/eslint/lib/eslint/eslint-helpers.js:323:20)
    at async Promise.allSettled (index 0)
    at async globMultiSearch (<redacted>/node_modules/eslint/lib/eslint/eslint-helpers.js:414:18)
    at async findFiles (<redacted>/node_modules/eslint/lib/eslint/eslint-helpers.js:585:24)
    at async ESLint.lintFiles (<redacted>/node_modules/eslint/lib/eslint/eslint.js:756:21)
    at async Object.execute (<redacted>/node_modules/eslint/lib/cli.js:603:14)
    at async main (<redacted>/node_modules/eslint/bin/eslint.js:160:19)

This is due to the flat/recommended config using plugins: { depend: plugin } but then the associated plugin is not the same instance as the one from my configuration file (quite obviously, given the import * as depend).

Ideally, I think that the plugin object should be exported as the default export (whether you like it or not), like in the ESLint documentation about writing plugins (according to the docs, it also allows applying it from the command line with --plugin depend, e.g. npx eslint --plugin depend --rule 'depend/ban-dependencies: error'), then the "final" configuration would be:

import { defineConfig } from "eslint/config";
import depend from "eslint-plugin-depend";

export default defineConfig([
  {
    files: ["**/*.js"],
    plugins: {
      depend,
    },
    extends: ["depend/flat/recommended"],
  }
]);

(edit: removed the part about depend.plugin as it's actually not exported so my analysis was incorrect, I assume it was equivalent to depend: undefined in my testing and ESLint is OK with that)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions