这是indexloc提供的服务,不要输入任何密码
Skip to content

Support name field in flat config and recommend as an convention #18231

@antfu

Description

@antfu

ESLint version

v9.0.0-rc.0

What problem do you want to solve?

(This is more like an RFC, but since it's rather simple, I started here first, but up to moving it to a proper RFC if you think it's necessary)

The new flat config format is truly great in many ways - I guess I don't need to list them - but thank you for making this move!

While it's great and much more composable, I often find it hard to tell the meaning/scope of each flat config item just by looking at the config among a large number of configs.

That's why I made https://github.com/antfu/eslint-flat-config-viewer, an interactive web UI to display the resolved flat configure structure with a search to understand how rules are applied. But still - given that the flat config items are anonymous, it not obvious what config are for what purpose.

Thus in the config viewer, and my own eslint-config, I spontaneously invented the convention of having that name field convention in my config and displaying name in the viewer. for example like this:

import eslint from '@eslint/js'

export default [
  {
    name: 'eslint:js', // assign custom name to other config
    ...eslint 
  }, 
  {
    name: 'antfu:ts',
    // ts plugins & rules...
  },
  {
    name: 'antfu:vue',
    // vue plugins & rules...
  }
  {
    name: 'antfu:vue:disables':
    // ...
  }
]
Screenshot 2024-03-26 at 14 46 39

Which I believe helps a lot on communications as well as some userland overrides like:

flatConfigs
    .find(c => c.name === 'stylistic')
    .rules['indent'] = 'off'

export default flatConfigs

What do you think is the correct solution?

Even if it "kinda works" right now, as ESLint is not compliant about the extra name properties (#17842 (comment)). But I think it would be great for the ecosystem to make it an official supported way and develop a convention across the ecosystem. The shared configs from plugins could have their plugin name as the prefix for their configs for example.

To achieve that, I think we could:

  • Add name to the flat config schema, and add it in @types/eslint
  • Add a doc section to recommend plugins/configs authors to provide that field with a convention (could be namespace:scope:sub-scope or namespace/scope etc, but more like a convention, not a constraint)
  • Integrations like https://github.com/antfu/eslint-flat-config-viewer could follow up that convention to provide a better DX for users,

Participation

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

Additional comments

No response

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussioncoreRelates 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