fix(next-codemod): handle CommonJS legacy ESLint configs in next-lint…#95710
Open
Alexoswin wants to merge 1 commit into
Open
fix(next-codemod): handle CommonJS legacy ESLint configs in next-lint…#95710Alexoswin wants to merge 1 commit into
Alexoswin wants to merge 1 commit into
Conversation
…-to-eslint-cli The next-lint-to-eslint-cli codemod assumed @eslint/migrate-config always generates eslint.config.mjs. The migration tool actually keeps the extension of JS legacy configs (.eslintrc.js -> eslint.config.js, .eslintrc.cjs -> eslint.config.cjs), so the codemod crashed with "Failed to find the expected output file" for those formats. Detect the generated flat config instead of hardcoding the .mjs name, and emit require() declarations instead of ESM import statements when updating a CommonJS flat config so the result stays loadable. Fixes vercel#85679
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
The
next-lint-to-eslint-clicodemod assumed that@eslint/migrate-configalways generateseslint.config.mjs. In practice, the migration tool preserves the module format of JavaScript-based legacy configs:.eslintrc.js→eslint.config.js.eslintrc.cjs→eslint.config.cjsBecause of this assumption, the codemod failed with:
when migrating projects using CommonJS ESLint configs.
This change detects whichever flat config file was actually generated instead of hardcoding
eslint.config.mjs. It also preserves the module system when updating CommonJS configs by generatingrequire()declarations instead of ESMimportstatements.Why?
next linthas been removed in Next.js 16, making this codemod the recommended migration path. Projects using.eslintrc.jsor.eslintrc.cjscurrently cannot complete the migration because the codemod crashes before finishing.Additionally, even if the generated file were found, the previous implementation would have inserted ESM imports into a CommonJS config, resulting in an invalid ESLint configuration.
How?
.mjs,.js, or.cjs) instead of assuming a fixed filename.require()declarations for CommonJS configs while preserving the existing ESM behavior for.mjsconfigs..eslintrc.cjsconfiguration.Testing
.eslintrc.cjsmigration.next-codemodtest suite successfully.eslint.config.cjsworks with ESLint 9 in a real sample project.Fixes #85679