oxc-project / oxc

⚓ A collection of JavaScript tools written in Rust.
https://oxc.rs
MIT License
12.45k stars 454 forks source link

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

Closed axetroy closed 1 month ago

axetroy commented 2 months ago
<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

DonIsaac commented 1 month ago

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

shulaoda commented 1 month ago

@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.

Boshen commented 1 month ago

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 Githubissues.

  • Githubissues is a development platform for aggregating issues.