chore: Migrate to ESLint flat configuration#21287
Conversation
0550794 to
bf4731e
Compare
Merge Checks Failed |
spartacus
|
||||||||||||||||||||||||||||
| Project |
spartacus
|
| Branch Review |
chore/migrate-eslint-flat-config
|
| Run status |
|
| Run duration | 04m 27s |
| Commit |
|
| Committer | sdrozdsap |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
3
|
|
|
0
|
|
|
0
|
|
|
101
|
| View all changes introduced in this branch ↗︎ | |
bf4731e to
55ebb46
Compare
55ebb46 to
d30e9d7
Compare
d30e9d7 to
3b5f6eb
Compare
Merge Checks Failed |
Merge Checks Failed |
pawelfras
left a comment
There was a problem hiding this comment.
Nitpick: Let's update comments in our custom eslint rules to point to the proper rule name, e.g:
- NOTE: The rule will be available in ESLint configs as "@nrwl/nx/workspace/no-ngrx-fail-action-without-error-action-implementation"
+ NOTE: The rule will be available in ESLint configs as "@/nx/workspace-no-ngrx-fail-action-without-error-action-implementation"Also, let's remember to inform tribe about the change and required "eslint.useFlatConfig": true in VSC config
| { | ||
| files: ['**/*.module.ts'], | ||
| plugins: { '@nx': nxPlugin }, | ||
| rules: { | ||
| '@nx/workspace-use-provide-default-config': 'error', | ||
| '@nx/workspace-use-provide-default-config-factory': 'error', | ||
| '@nx/workspace-use-provide-default-feature-toggles': 'error', | ||
| '@nx/workspace-use-provide-default-feature-toggles-factory': 'error', | ||
| }, | ||
| }, |
There was a problem hiding this comment.
query: is this a recommended way of using our custom rules? I couldn't find it in the official Nx docs: https://nx.dev/docs/technologies/eslint/guides/custom-workspace-rules
There was a problem hiding this comment.
To be honest, I'm not sure if its recommended or not. I think this is similar to what we had before, and I didn't give much thought about how we can refactor or change it. This approach is tested and works, but if you see any issue with it Im open minded for the change
|
@pawelfras about that:
I actually don't have "eslint.useFlatConfig": true and it still works since flat config is the default now. Doesn't it work without it in your case? |
Only now I realised we have ESLint version > 9.0.0, so the config is set to true by default. Indeed, it works without setting it explicitly to true. Thanks!
|

Migrate to ESLint flat configuration
This PR migrates from the old
.eslintrc.jsonformat to the new ESLint flat config (eslint.config.mjs). The old format is deprecated and will eventually stop being supported, so this is something we needed to do sooner or later.Some ESLint-related packages were updated and redundant sub-packages removed since they're now bundled.
Issues found along the way
After the migration, linting started failing for 7 projects:
storefrontlib,core,order,opf,cpq-quote,setup, andstorefrontapp. After investigating each failure, here's what was going on:no-consolewas silently broken before. Turns out the old config had a bug wherelegacy-ng-cli-compat.jsonwas quietly overriding our strictno-console: "error"with a broad allow list that included"log". Soconsole.logwas effectively allowed everywhere, even though it wasn't supposed to be. The flat config now correctly enforces the intended behaviour. I removed a few leftover debugconsole.logs from spec files and addedeslint-disablewhereconsoleusage is intentional (test assertions likeexpect(console.warn), a mock logger, and the build-time env log instorefrontapp/esbuild/plugins.ts).Nx workspace rule names changed format. In the old config rules were named like
@nx/workspace/rule-name, but flat config registers them as@nx/workspace-rule-name(with a dash). Someeslint-disablecomments incorereferenced the old names, so those were updated.For details see
A bunch of
eslint-disablecomments became unnecessary. Rules likemax-len,no-bitwise,import/no-deprecatedetc. are no longer active in the new config, so their disable directives were just noise. Cleaned those upAlso deleted
tools/eslint-plugins/legacy-ng-cli-compat.jsonandlegacy-ng-cli-compat--formatting-add-on.json. I couldn't find any reason to keep them around.QA
Also you can manually break some linting rule and check if your IDE highlights it