oxc
oxc copied to clipboard
linter: `no-useless-spread` fixer clobbers code before span in Vue script block
<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 what happens when you run oxlint --fix?
@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.
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