Skip to content

[eslint plugin query] infinite-query-property-order crashes with object spread #8156

@TkDodo

Description

@TkDodo

Here’s a failing test-case for the rule infinite-query-property-order

{
  name: 'should work with object spread',
  code: normalizeIndent`
  return useInfiniteQuery({
    ...myOptions.infiniteQueryOptions(),
    refetchInterval: 10 * 1000,
  })`,
},

crashes with:

Error: Unsupported spread element
Occurred while linting file.ts:2
Rule: "@rule-tester/infinite-query-property-order"
 ❯ flatMap src/rules/infinite-query-property-order/infinite-query-property-order.rule.ts:91:17
     89|             const reorderedText = sortedProperties.reduce(
     90|               (sourceText, specifier, index) => {
     91|                 let textBetweenProperties = ''
       |                 ^
     92|                 if (index < allProperties.length - 1) {
     93|                   textBetweenProperties = sourceCode

Note that it starts to work if the spread looks like this:

{
  name: 'should work with object spread',
  code: normalizeIndent`
  return useInfiniteQuery({
-    ...myOptions.infiniteQueryOptions(),
+    ...infiniteQueryOptions(),
    refetchInterval: 10 * 1000,
  })`,
},

so it seems to be about accessing a property of an object. Just ...myOptions.infiniteQueryOptions also fails

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions