Skip to content

Change Request: Improve error message when a plugin's rules are enabled without the plugin #19254

@bradgarropy

Description

@bradgarropy

ESLint version

v9.17.0

What problem do you want to solve?

In my example, I was using defining rules for simple-import-sort on a file set where the simple-import-sort plugin was not included.

import simpleImportSort from 'eslint-plugin-simple-import-sort';

const config = [
  {
    files: ['**/*.ts'],
    plugins: {
      'simple-import-sort': simpleImportSort,
    },
  },
  {
    rules: {
      'simple-import-sort/imports': ['error'],
    },
  },
];

export default config;

This results in a confusing error message:

Oops! Something went wrong! :(

ESLint: 9.17.0

TypeError: Key "rules": Key "simple-import-sort/imports": Could not find plugin "simple-import-sort".
    at throwRuleNotFoundError (file:///home/projects/no-irregular-whitespace-rvqwyakg/node_modules/eslint/lib/config/rule-validator.js#cjs:66:11)
    at RuleValidator.validate (file:///home/projects/no-irregular-whitespace-rvqwyakg/node_modules/eslint/lib/config/rule-validator.js#cjs:147:17)
    at new Config (file:///home/projects/no-irregular-whitespace-rvqwyakg/node_modules/eslint/lib/config/config.js#cjs:228:27)
    at [finalizeConfig] (file:///home/projects/no-irregular-whitespace-rvqwyakg/node_modules/eslint/lib/config/flat-config-array.js#cjs:216:16)
    at FlatConfigArray.getConfigWithStatus (file:///home/projects/no-irregular-whitespace-rvqwyakg/node_modules/@eslint/config-array/dist/cjs/index.cjs#cjs:1178:55)
    at FlatConfigArray.getConfig (file:///home/projects/no-irregular-whitespace-rvqwyakg/node_modules/@eslint/config-array/dist/cjs/index.cjs#cjs:1196:15)
    at entryFilter (file:///home/projects/no-irregular-whitespace-rvqwyakg/node_modules/eslint/lib/eslint/eslint-helpers.js#cjs:282:40)
    at async NodeHfs.eval (file:///home/projects/no-irregular-whitespace-rvqwyakg/node_modules/@humanfs/core/src/hfs.js:591:24)
    at async NodeHfs.walk (file:///home/projects/no-irregular-whitespace-rvqwyakg/node_modules/@humanfs/core/src/hfs.js:631:3)
    at async globSearch (file:///home/projects/no-irregular-whitespace-rvqwyakg/node_modules/eslint/lib/eslint/eslint-helpers.js#cjs:323:26)

Minimal Reproduction

https://stackblitz.com/edit/no-irregular-whitespace-rvqwyakg

What do you think is the correct solution?

It would help to have a more descriptive error message stating that the plugin I was trying to write rules for is defined in another configuration object. Even better if it could reference the line where it was included.

For example:

Oops! Something went wrong! :(

ESLint: 9.17.0

TypeError: Key "rules": Key "simple-import-sort/imports": The plugin you are referencing ("simple-import-sort") is defined in a different configuration object.

eslint.config.ts:6-8

    plugins: {
      'simple-import-sort': simpleImportSort,
    },

Participation

  • I am willing to submit a pull request for this change.

Additional comments

/cc @JoshuaKGoldberg

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusioncoreRelates to ESLint's core APIs and featuresenhancementThis change enhances an existing feature of ESLint

    Type

    No type

    Projects

    Status

    Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions