-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(linter): handle various flat config override structures #33548
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit 19fc5b4
☁️ Nx Cloud last updated this comment at |
meeroslav
left a comment
There was a problem hiding this 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
There was a problem hiding this 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) {
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
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
|
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. |
Flat config overrides util may fail when it isn't a plain JS object. This PR makes the
hasOverridesfunction more robust against these cases.Fixes #31796