Skip to content

Invalid flat eslint configuration for new projects #30774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 4 tasks
moxaj opened this issue Apr 17, 2025 · 2 comments
Open
1 of 4 tasks

Invalid flat eslint configuration for new projects #30774

moxaj opened this issue Apr 17, 2025 · 2 comments

Comments

@moxaj
Copy link

moxaj commented Apr 17, 2025

Current Behavior

I've created a brand new project (angular monorepo) which uses flat eslint configuration. The generated project has a root level eslint.config.mjs, and also has one for the single application. However, eslint only ever considers the top level config as per this blog post. So, the whole setup is invalid; the app level configuration is never read. Therefore, for cypress tests for example, one cannot ignore cypress-specific eslint warnings because cypress.configs['recommended'] is never applied (it'd have to be at the root level).

Expected Behavior

I'd expect that monorepos using flat esconfig would have the correct configuration (single top-level eslint.config.mjs) with the proper setup.

GitHub Repo

No response

Steps to Reproduce

  1. create a new workspace with npx create-nx-workspace (angular / integrated monorepo / esbuild / sass / jest / cypress)
  2. add this extra line to /apps/example-project-e2e/src/e2e/app.cy.ts:
    // eslint-disable-next-line cypress/no-assigning-return-values
  3. lint the generated e2e test files with npx eslint apps/example-project-e2e/**
  4. observe the error 4:1 error Definition for rule 'cypress/no-assigning-return-values' was not found cypress/no-assigning-return-values

Nx Report

Node           : 20.17.0
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 10.2.3

nx                     : 20.8.0
@nx/js                 : 20.8.0
@nx/jest               : 20.8.0
@nx/eslint             : 20.8.0
@nx/workspace          : 20.8.0
@nx/angular            : 20.8.0
@nx/cypress            : 20.8.0
@nx/devkit             : 20.8.0
@nx/eslint-plugin      : 20.8.0
@nx/module-federation  : 20.8.0
@nx/rspack             : 20.8.0
@nx/web                : 20.8.0
@nx/webpack            : 20.8.0
typescript             : 5.7.3
---------------------------------------
Registered Plugins:
@nx/cypress/plugin
@nx/eslint/plugin
---------------------------------------
Community plugins:
angular-eslint : 19.3.0
---------------------------------------
Cache Usage: 0.00 B / 47.57 GB

Failure Logs

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@thdk
Copy link
Contributor

thdk commented Apr 19, 2025

Hi @moxaj

You most likely have misinterpret the eslint documentation about flat config. It still allows each project to have its own eslint config file. However, it will no longer look for other eslint config files as soon as a config file has been found. The previous eslint configuration would merge all found eslint configurations file found in the entire file tree.

When the ESLint CLI is used, it searches for eslint.config.js from the current working directory and if not found will continue the search up the directory’s ancestors until the file is found or the root directory is hit. That one eslint.config.js file contains all of the configuration information

What goes wrong for you is that you are not running eslint for the specific project when you do:

npx eslint apps/example-project-e2e/**

but you are running eslint in the root folder instead. So there indeed the current working directory is the root folder and the root eslint config file will be used.

However, if you would do:

npx nx lint example-project-e2e

That would use the project folder as current working directory and the task will run without any issues.

~/repos/thdk/cypress-eslint (main ✗) npx nx lint test-e2e --skip-nx-cache

> nx run test-e2e:lint

> eslint .


/Users/thdk/repos/thdk/cypress-eslint/apps/test-e2e/src/e2e/app.cy.ts
  3:1  warning  Unused eslint-disable directive (no problems were reported from 'cypress/no-assigning-return-values')

✖ 1 problem (0 errors, 1 warning)
  0 errors and 1 warning potentially fixable with the `--fix` option.

Note that there are two syntaxes for run tasks with nx:

# npx nx run [project-name]:[target-name]:[configuration-name]
npx nx run example-project-e2e:lint

# npx nx [target-name] [project-name] --configuration [configuration-name]
npx nx lint example-project-e2e

(configuration-name is optional and not required here)

See docs:

@moxaj
Copy link
Author

moxaj commented Apr 19, 2025

I see. The reason this came up was that I could not longer commit certain files as the pre-commit hook failed (husky + lint-staged), as my lint-staged configuration in package.json was something like { "*.ts": "eslint" }, and that obviously runs from the root folder, ignoring the project specific eslint configuration. I guess I have to make that a bit more sophisticated ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants