Skip to content
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

Full support for esm flat configs #1834

Closed
runspired opened this issue Apr 20, 2024 · 10 comments
Closed

Full support for esm flat configs #1834

runspired opened this issue Apr 20, 2024 · 10 comments
Labels
info-needed Issue requires more information from poster

Comments

@runspired
Copy link

runspired commented Apr 20, 2024

Currently this extension appears to only find eslint configuration files when:

  • using eslint.config.cjs
  • using eslint.config.js with "type": "module" in package.json

It currently does not appear to find configuration files when:

  • using an ESM eslint.config.js without "type": "module" in package.json
  • using eslint.config.mjs

Other things to note:

  • Linting works correctly from the terminal.
  • I am using the latest pre-release v3.0.5 (pre-release)
  • I have configured flat config in settings: "eslint.useFlatConfig": true,
  • I am using eslint "8.57.0" (v9 contains changes beyond the move to flat config that are not supported yet by @babel/eslint-parser @babel/eslint-plugin: Support ESLint 9 babel/babel#16220)
@dbaeumer
Copy link
Member

@runspired which package manager are you using? If you use yarn you are very likely affect by: yarnpkg/berry#6219

If you don't use yarn, can you please provide me with a GitHub repository I can clone with a minimal setup that demos this.

I do have a mjs test case here so it work in principal:

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Apr 22, 2024
@runspired
Copy link
Author

@dbaeumer pnpm monorepo, this branch has the work in it: emberjs/data#9292

@Zamiell
Copy link

Zamiell commented May 2, 2024

I am also using "eslint.config.mjs" in the root of my repo and this extension fails to find it. The "type" field in the "package.json" file is module, and it still doesn't work:

No ESLint configuration (e.g .eslintrc) found for file: d:\Repositories\isaacscript\packages\eslint-config-isaacscript\base.js
File will not be validated. Consider running 'eslint --init' in the workspace folder isaacscript
Alternatively you can disable ESLint by executing the 'Disable ESLint' command.

@dbaeumer
Copy link
Member

dbaeumer commented May 6, 2024

@Zamiell which version are you using. Falt config support need currently 3.0.5-pre-release version of the eslint extension.

@dbaeumer
Copy link
Member

dbaeumer commented May 6, 2024

@runspired after removing "eslint.options": { "reportUnusedDisableDirectives": "error" }, from the settings (which is not support anymore that way in ESLint itself) linitng works for me. I get this in the output channel:

2024-05-06T09:13:51.303Z eslint:flat-eslint Searching for eslint.config.js
2024-05-06T09:13:51.307Z eslint:flat-eslint Loading config from /workspaces/data/packages/graph/eslint.config.mjs
2024-05-06T09:13:51.307Z eslint:flat-eslint Config file URL is file:///workspaces/data/packages/graph/eslint.config.mjs
2024-05-06T09:13:51.311Z eslint:flat-eslint Searching for eslint.config.js
2024-05-06T09:13:51.312Z eslint:flat-eslint Loading config from /workspaces/data/packages/graph/eslint.config.mjs
2024-05-06T09:13:51.312Z eslint:flat-eslint Config file URL is file:///workspaces/data/packages/graph/eslint.config.mjs
2024-05-06T09:13:51.317Z eslint:flat-eslint Lint /workspaces/data/packages/graph/src/-private.ts
2024-05-06T09:13:51.317Z eslint:linter Linting code for /workspaces/data/packages/graph/src/-private.ts (pass 1)
2024-05-06T09:13:51.317Z eslint:linter Verify
2024-05-06T09:13:51.317Z eslint:linter With flat config: /workspaces/data/packages/graph/src/-private.ts
2024-05-06T09:13:51.317Z eslint:linter Parsing: /workspaces/data/packages/graph/src/-private.ts
2024-05-06T09:13:52.059Z eslint:linter Parsing successful: /workspaces/data/packages/graph/src/-private.ts
2024-05-06T09:13:52.059Z eslint:linter Scope analysis: /workspaces/data/packages/graph/src/-private.ts
2024-05-06T09:13:52.059Z eslint:linter Scope analysis successful: /workspaces/data/packages/graph/src/-private.ts
2024-05-06T09:13:52.121Z eslint:linter Generating fixed text for /workspaces/data/packages/graph/src/-private.ts (pass 1)
2024-05-06T09:13:52.121Z eslint:source-code-fixer Applying fixes
2024-05-06T09:13:52.121Z eslint:source-code-fixer shouldFix parameter was false, not attempting fixes
2024-05-06T09:13:52.121Z eslint:flat-eslint Linting complete in: 809ms

Anything I am missing?

@runspired
Copy link
Author

@dbaeumer I'll try that out!

@runspired
Copy link
Author

@dbaeumer indeed removing that from config seems to make everything work as expected!

If we want our editor to report unused directives now, how do we go about that?

@Zamiell
Copy link

Zamiell commented May 6, 2024

which version are you using. Falt config support need currently 3.0.5-pre-release version of the eslint extension.

sorry, i didn't understand that. i have linting working now on the alpha version, sorry for the noise.

If we want our editor to report unused directives now, how do we go about that?

historically in the ecosystem people have used this: https://github.com/eslint-community/eslint-plugin-eslint-comments
it is superior imho because you get the warnings as actual eslint rule instead of from an esoteric eslint flag!
(the former is easier to synchronize across a development team)

@trylovetom
Copy link

change to

{
  "eslint.experimental.useFlatConfig": true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants