Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Change Request: allow default as known key for interoperation between commonjs and ESM #19703

@JounQin

Description

@JounQin

ESLint version

v9.26.0

What problem do you want to solve?

eslint-config-prettier is commonjs only + exports.rules/exports.name, so import * as eslintConfigPrettier from 'eslint-config-prettier' should be used when using eslint.config.mjs, but node will add an extra default property on eslintConfigPrettier in this case.

import * as eslintConfigPrettier from 'eslint-config-prettier'

console.log(Object.keys(eslintConfigPrettier)) // [ 'default', 'rules' ]

import * as eslintConfigPrettierFlat from 'eslint-config-prettier/flat'

console.log(Object.keys(eslintConfigPrettierFlat)) // [ 'default', 'name', 'rules' ]

But those can not be used directly as ESLint flat config due to the default property:

Oops! Something went wrong! :(

ESLint: 9.26.0

ConfigError: Config (unnamed): Unexpected key "default" found.

What do you think is the correct solution?

  1. Ignore default key
  2. Ignore all unknown keys, I don't get why we're vailidating the unknown keys actually, for example, we had to add an extra /flat entry only for adding a new name property for flat config which is unavailable in eslintrc, this is a bit ridiculous to myself: fix: separate the /flat entry for compatibility prettier/eslint-config-prettier#309

Participation

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

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreRelates 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