Skip to content

Conversation

@jaysoo
Copy link
Member

@jaysoo jaysoo commented Nov 19, 2025

Flat config overrides util may fail when it isn't a plain JS object. This PR makes the hasOverrides function more robust against these cases.

Fixes #31796

@jaysoo jaysoo requested a review from a team as a code owner November 19, 2025 19:35
@jaysoo jaysoo requested a review from FrozenPandaz November 19, 2025 19:35
@vercel
Copy link

vercel bot commented Nov 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Nov 19, 2025 8:54pm

@netlify
Copy link

netlify bot commented Nov 19, 2025

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 19fc5b4
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/691e2d5ceb9b5f0008ec8214
😎 Deploy Preview https://deploy-preview-33548--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Nov 19, 2025

View your CI Pipeline Execution ↗ for commit 19fc5b4

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 30m 28s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 1m 45s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 10s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-19 21:40:36 UTC

Copy link
Contributor

@meeroslav meeroslav left a comment

Choose a reason for hiding this comment

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

Looks ok, apart from the test that Graphite already caught

Copy link
Contributor

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

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

Nx Cloud is proposing a fix for your failed CI:

The AST-based extraction introduced in this PR needed to handle dynamic imports (await import('jsonc-eslint-parser')) and require calls that are generated during flat config conversion. Without this, the parser property was being lost when configs were matched and replaced, causing ESLint to incorrectly parse JSON files as JavaScript. The enhanced extractLiteralValue function now extracts the module name from these expressions as strings, preserving parser configuration during config manipulation.

We could not verify this fix.

Suggested Fix changes
diff --git a/packages/eslint/src/generators/utils/flat-config/ast-utils.spec.ts b/packages/eslint/src/generators/utils/flat-config/ast-utils.spec.ts
index b6961e6dec..8adefd85a8 100644
--- a/packages/eslint/src/generators/utils/flat-config/ast-utils.spec.ts
+++ b/packages/eslint/src/generators/utils/flat-config/ast-utils.spec.ts
@@ -1328,6 +1328,51 @@ export default [
       );
       expect(result).toBe(true);
     });
+
+    it('should extract parser from dynamic import expressions', () => {
+      const content = `
+export default [
+    {
+        files: ['*.json'],
+        languageOptions: {
+            parser: await import('jsonc-eslint-parser')
+        },
+        rules: {
+            '@nx/dependency-checks': 'error'
+        }
+    }
+];`;
+
+      const result = hasOverride(
+        content,
+        (o) =>
+          Array.isArray(o.files) &&
+          o.files.includes('*.json') &&
+          (o as any).languageOptions?.parser === 'jsonc-eslint-parser'
+      );
+      expect(result).toBe(true);
+    });
+
+    it('should extract parser from require expressions in CJS', () => {
+      const content = `
+module.exports = [
+    {
+        files: ['*.json'],
+        languageOptions: {
+            parser: require('jsonc-eslint-parser')
+        }
+    }
+];`;
+
+      const result = hasOverride(
+        content,
+        (o) =>
+          Array.isArray(o.files) &&
+          o.files.includes('*.json') &&
+          (o as any).languageOptions?.parser === 'jsonc-eslint-parser'
+      );
+      expect(result).toBe(true);
+    });
   });
 
   describe('generatePluginExtendsElementWithCompatFixup', () => {
diff --git a/packages/eslint/src/generators/utils/flat-config/ast-utils.ts b/packages/eslint/src/generators/utils/flat-config/ast-utils.ts
index be46efa5d8..273bd8d8ee 100644
--- a/packages/eslint/src/generators/utils/flat-config/ast-utils.ts
+++ b/packages/eslint/src/generators/utils/flat-config/ast-utils.ts
@@ -236,6 +236,29 @@ function extractLiteralValue(node: ts.Node): unknown {
   if (node.kind === ts.SyntaxKind.FalseKeyword) return false;
   if (node.kind === ts.SyntaxKind.NullKeyword) return null;
 
+  // Handle await import('module') expressions - extract the module name as a string
+  // This is needed for parser properties that use dynamic imports
+  if (
+    ts.isAwaitExpression(node) &&
+    ts.isCallExpression(node.expression) &&
+    node.expression.expression.kind === ts.SyntaxKind.ImportKeyword &&
+    node.expression.arguments.length === 1 &&
+    ts.isStringLiteral(node.expression.arguments[0])
+  ) {
+    return node.expression.arguments[0].text;
+  }
+
+  // Handle require('module') expressions - extract the module name as a string
+  if (
+    ts.isCallExpression(node) &&
+    ts.isIdentifier(node.expression) &&
+    node.expression.text === 'require' &&
+    node.arguments.length === 1 &&
+    ts.isStringLiteral(node.arguments[0])
+  ) {
+    return node.arguments[0].text;
+  }
+
   if (ts.isArrayLiteralExpression(node)) {
     const arr: unknown[] = [];
     for (const element of node.elements) {

Apply fix via Nx Cloud  Reject fix via Nx Cloud

Or Apply changes locally with:

npx nx-cloud apply-locally uW9M-PzPo

Apply fix locally with your editor ↗   View interactive diff ↗


🎓 To learn more about Self Healing CI, please visit nx.dev

@jaysoo jaysoo merged commit 05bd3a4 into master Nov 19, 2025
20 checks passed
@jaysoo jaysoo deleted the NXC-3501 branch November 19, 2025 21:40
jaysoo added a commit that referenced this pull request Nov 19, 2025
Flat config overrides util may fail when it isn't a plain JS object.
This PR makes the `hasOverrides` function more robust against these
cases.


Fixes #31796
@github-actions
Copy link
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nx g @nx/plugin:plugin InvalidSymbol error with eslint.config.mjs file

3 participants