From f14cd5167880b2e9645bbcd7d7979efaeea6f8dd Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Mon, 21 Apr 2025 19:10:57 +0200 Subject: [PATCH] 117616: Allow CallExpressions like forwardRef in the standalone imports array as well --- lint/src/rules/ts/sort-standalone-imports.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lint/src/rules/ts/sort-standalone-imports.ts b/lint/src/rules/ts/sort-standalone-imports.ts index 30a2a5bca8..fa8d45becc 100644 --- a/lint/src/rules/ts/sort-standalone-imports.ts +++ b/lint/src/rules/ts/sort-standalone-imports.ts @@ -101,12 +101,12 @@ export const rule = ESLintUtils.RuleCreator.withoutDocs({ create(context: TSESLint.RuleContext, [{ locale, maxItems, indent, trailingComma }]: any) { return { ['ClassDeclaration > Decorator > CallExpression[callee.name="Component"] > ObjectExpression > Property[key.name="imports"] > ArrayExpression']: (node: TSESTree.ArrayExpression) => { - const identifiers = node.elements.filter(TSESLintASTUtils.isIdentifier); - const sortedNames: string[] = identifiers - .map((identifier) => identifier.name) + const elements = node.elements.filter((element) => element !== null && (TSESLintASTUtils.isIdentifier(element) || element?.type === TSESTree.AST_NODE_TYPES.CallExpression)); + const sortedNames: string[] = elements + .map((element) => context.sourceCode.getText(element!)) .sort((a: string, b: string) => a.localeCompare(b, locale)); - const isSorted: boolean = identifiers.every((identifier, index) => identifier.name === sortedNames[index]); + const isSorted: boolean = elements.every((identifier, index) => context.sourceCode.getText(identifier!) === sortedNames[index]); const requiresMultiline: boolean = maxItems < node.elements.length; const isMultiline: boolean = /\n/.test(context.sourceCode.getText(node));