Skip to content

Bug: [Flat config] Errors should indicate which config object contains error #18926

Closed
@broofa

Description

@broofa

[My apologies for not using the template to provide an executable MRE. Hopefully this problem is self-evident enough that's not needed]

Environment

$ npx eslint --env-info
Environment Info:

Node version: v20.16.0
npm version: v10.8.1
Local ESLint version: v9.10.0 (Currently used)
Global ESLint version: Not found
Operating System: darwin 23.5.0

Problem

As mentioned in the title, if a eslint.config.js file exports an array of configs with more than one item, diagnosing which config object has the error can be problematic.

Example

The config: eslint.config.js

 // Note: Invalid plugins object structure in 3rd config object
export default [ {}, {}, {  plugins: ['react'] }, {} ]

The error

$ eslint .

Oops! Something went wrong! :(

A config object has a "plugins" key defined as an array of strings.

Flat config requires "plugins" to be an object in this form:

    {
        plugins: {
            react: pluginObject
        }
    }

NOTE: Log output fails to show which of the four config objects has the bad plugins key. This puts the user in the position of having to guess and/or use trial and error to track down which of the four config objects is the problem.

This becomes particularly problematic as the size and complexity of the array grows. For example, our (CodePen's) current config setup has a dozen different config objects:

export default [
  js.configs.recommended,
  ...eslintTypescript.configs.recommended,
  eslintImport.flatConfigs.recommended,
  eslintJest.configs['flat/recommended'],
  eslintPromise.configs['flat/recommended'],
  eslintReact.configs.flat.recommended,
  eslintReactHooksFlat,
  eslintSonar.configs.recommended,
  eslintUnicorn.configs.recommended,

  // custom configs
  codepenIgnores,
  codepenGraphql,
  codepenRailsGraphql
];

Solution (Proposed)

Option 1: include config index in error

At a minimum, including the index of the config object in the error message would be helpful. For example...

A config object Config object at index 2 has a "plugins" key defined as an array of strings.

Option 2: support config#name property on config objects, and include in error

For example, with this config...

export default [ 
 { name: 'oneConfig' },  
 { name: 'twoConfig' }, 
 { name: 'redConfig', plugins: ['react'] }, 
 { name: 'blueConfig' }
]

... the error might read:

A config object "redConfig#plugins" key defined as an array of strings.

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionenhancementThis 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

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy