Skip to content

Commit f14cd51

Browse files
117616: Allow CallExpressions like forwardRef in the standalone imports array as well
1 parent f0a00ac commit f14cd51

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lint/src/rules/ts/sort-standalone-imports.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ export const rule = ESLintUtils.RuleCreator.withoutDocs({
101101
create(context: TSESLint.RuleContext<Message, unknown[]>, [{ locale, maxItems, indent, trailingComma }]: any) {
102102
return {
103103
['ClassDeclaration > Decorator > CallExpression[callee.name="Component"] > ObjectExpression > Property[key.name="imports"] > ArrayExpression']: (node: TSESTree.ArrayExpression) => {
104-
const identifiers = node.elements.filter(TSESLintASTUtils.isIdentifier);
105-
const sortedNames: string[] = identifiers
106-
.map((identifier) => identifier.name)
104+
const elements = node.elements.filter((element) => element !== null && (TSESLintASTUtils.isIdentifier(element) || element?.type === TSESTree.AST_NODE_TYPES.CallExpression));
105+
const sortedNames: string[] = elements
106+
.map((element) => context.sourceCode.getText(element!))
107107
.sort((a: string, b: string) => a.localeCompare(b, locale));
108108

109-
const isSorted: boolean = identifiers.every((identifier, index) => identifier.name === sortedNames[index]);
109+
const isSorted: boolean = elements.every((identifier, index) => context.sourceCode.getText(identifier!) === sortedNames[index]);
110110

111111
const requiresMultiline: boolean = maxItems < node.elements.length;
112112
const isMultiline: boolean = /\n/.test(context.sourceCode.getText(node));

0 commit comments

Comments
 (0)