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

fix: correct defineConfig usage in generated config #161

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

snitin315
Copy link
Contributor

@snitin315 snitin315 commented Mar 28, 2025

Fix #160

  • Added a regular expression to check if a version requirement allows ESLint 9.22.0 or higher.
  • Conditional Import: Introduced logic to import defineConfig based on the ESLint version requirement conditionally.
  • Version Check: Implemented checks for complex and simple version requirements to ensure compatibility with ESLint 9+.

@eslint-github-bot eslint-github-bot bot added the bug Something isn't working label Mar 28, 2025
@snitin315 snitin315 marked this pull request as draft March 28, 2025 02:06
@snitin315 snitin315 marked this pull request as ready for review March 28, 2025 02:50
@snitin315 snitin315 marked this pull request as draft March 28, 2025 02:56
@snitin315 snitin315 marked this pull request as ready for review March 31, 2025 03:50

this.result.configContent = `${importContent}
${needCompatHelper ? helperContent : ""}
export default defineConfig([\n${exportContent || " {}\n"}]);`; // defaults to `[{}]` to avoid empty config warning
export default ${isDefineConfigExported ? `defineConfig(${exportContent})` : exportContent};`; // defaults to `[{}]` to avoid empty config warning
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach won't work because we are using the extends key elsewhere, which requires defineConfig().

Instead, if defineConfig isn't an export of the eslint package, we should install @eslint/config-helpers and import it from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, updated 👍🏻

* - "9.22" or higher versions without prefix
* - Correctly handles full semver notation (e.g., 9.22.0, ~9.22.0)
*/
const ESLINT_9_PLUS_REGEX = /\^9|>=\s*9|(?:~|^)9\.(2[2-9]|[3-9]\d|\d{3,})/u;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would make sense to use the semver package instead? That way we could eliminate one source of bugs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we can use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated 👍🏻

@@ -119,7 +120,8 @@ export class ConfigGenerator {
const languages = this.answers.languages ?? ["javascript"];
const purpose = this.answers.purpose;

let importContent = "import { defineConfig } from \"eslint/config\";\n";
let isDefineConfigExported = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to change to the default to true, as:

devDependencies: ["eslint"],
?

so the only thing is to change it to false when [email protected] is not allowed.

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending answer to @aladdin-add's question.

@aladdin-add
Copy link
Member

@snitin315 your feedback is wanted here. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './config' is not defined by "exports"
3 participants