nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.82k stars 2.38k forks source link

Eslint does not support common/module suffixes for Flat Config #22576

Open JacobLey opened 8 months ago

JacobLey commented 8 months ago

Current Behavior

Eslint's new Flat Config supports 3 names:

Supported suffixes comes from Eslint's documentation directly: This is quoted from Eslint's documentation itself: https://eslint.org/docs/latest/use/configure/configuration-files-new#configuration-file

The ESLint configuration file may be named any of the following:

However Nx's eslint does not recognize anything other than eslint.config.js.

This means it is not possible to explictly use CommonJS or ESM, especially if the desired format differs from what is in package.json

Expected Behavior

Nx's eslint respects all 3 file extensions for Flat Config

GitHub Repo

No response

Steps to Reproduce

1.

Nx Report

Node   : 20.11.1
OS     : linux-arm64
npm    : 10.2.4

nx (global)  : 18.1.3
nx           : 18.1.3
@nrwl/tao    : 18.1.3

Failure Logs

When using the new Flat Config with ESLint, all configs must be named eslint.config.js and .eslintrc files may not be used. See https://eslint.org/docs/latest/use/configure/configuration-files-new

Package Manager Version

pnpm 8.15.4

Operating System

Additional Information

Eslint executor versin: "@nx/eslint": "18.1.3"

This issue is admittedly light on reproducability, because I can just point directly in the code where these issues are occuring.

The following places explicitly hard code the eslint.config.js filename, and do not account for other extensions:

bneigher commented 7 months ago

yea this is preventing me from my eslint 9 migration :/

blordpluto commented 6 months ago

Hi 👋 Can the team please offer some sort of expected timetable for this to be resolved? Flat config is the default in ESLint 9, which has been out for over a month now. Flat config itself has been available since 2022. For something very basic like this, we really would appreciate a bit more transparency about any scheduled fix. Thanks!

jotwea commented 5 months ago

The solution for this issue might be here - there is already a TODO: https://github.com/nrwl/nx/blob/master/packages/eslint/src/utils/config-file.ts#L4

export const ESLINT_FLAT_CONFIG_FILENAMES = ['eslint.config.js', 'eslint.config.mjs', 'eslint.config.cjs'];

ak274 commented 5 months ago

Is there any plan to support flat config by default while creating new workspaces? Because flat config is now default and recommended in ESLint Docs.

https://eslint.org/blog/2024/04/eslint-v9.0.0-released/#flat-config-is-now-the-default-and-has-some-changes

robertIsaac commented 5 months ago

@ak274 I have already requested it https://github.com/nrwl/nx/discussions/26338, so far no news

robertIsaac commented 4 months ago

hi @benpsnyder I see you have added support for .cjs but not .mjs and added TODO for it when do we expect the .mjs to be done?

benpsnyder commented 4 months ago

hi @benpsnyder

I see you have added support for .cjs but not .mjs and added TODO for it

when do we expect the .mjs to be done?

Adding support for .cjs was easy but I don't plan to work on .mjs at this time which will be harder to implement. I just solved the quick and easy task for now.

robertIsaac commented 4 months ago

Can you explain what is hard about it I can try to work on it on the weekend

alfaproject commented 3 months ago

I just stumbled upon this as well, got a bit surprised when .mjs didn't work ):

kuda1992 commented 2 months ago

When is this going to be fixed? Do you have a timeline? I am not able to use eslint.config.mjs

codinronan commented 2 months ago

For anyone who wants to use eslint.config.mjs you can do so now, you just end up forced to manually specify the lint task in your project.json files (since the config file is not picked up by the plugin, so the lint task is not automatically generated).

In my case, since we just use the simplest eslint . command it isn't a problem, but if you have a more complicated setup I guess it could be an issue.

Incidentally I do also have type: module in my package.json files so this may be why this works, I haven't tried changing it to commonjs since our build stack requires module anyway.

Stanzilla commented 6 days ago

@JamesHenry Would this be just adding the file name to https://github.com/nrwl/nx/blob/master/packages/eslint/src/utils/flat-config.ts#L5 here is there more? Willing to contribute if it is easy.