oxc icon indicating copy to clipboard operation
oxc copied to clipboard

linter: `no-useless-spread` fixer clobbers code before span in Vue script block

Open axetroy opened this issue 1 year ago • 3 comments

<template>
    <div>Hello world</div>
</template>

<script lang="js">
const isCondition = true

const bar = {
    ...(isCondition ? { a: 1 } : { b: 2 })
}

export default {
    data() {
        bar
    }
}
</script>
  ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-useless-spread.html\eslint-plugin-unicorn(no-useless-spread)]8;;\: Using a spread operator here creates a new object unnecessarily.
   ,-[src\renderer\App.vue:5:5]
 4 | const bar = {
 5 |     ...(isCondition ? { a: 1 } : { b: 2 })
   :     ^^^
 6 | }
   `----
  help: `isCondition ? { a: 1 } : { b: 2 }` returns a new object. Spreading it into an object expression to create a new object is redundant.

And here is the fix:

https://github.com/user-attachments/assets/ebd3752f-a791-481c-8baa-7ec8ae022822

axetroy avatar Sep 20 '24 07:09 axetroy

@axetroy what happens when you run oxlint --fix?

DonIsaac avatar Sep 24 '24 18:09 DonIsaac

@axetroy what happens when you run oxlint --fix?

I tried to reproduce it and found that the file was not fixed through oxlint --fix.

This seems to be because the --fix does not work on .vue files, which is normal for .js and .ts.

shulaoda avatar Sep 24 '24 20:09 shulaoda

We need to ignore it in IDE as well, or actually fix the root cause.

The root cause is the fixer need to be offset by the

Boshen avatar Sep 25 '24 02:09 Boshen