🐛 `lint/complexity/useSimplifiedLogicExpression` quick fix breaks
Environment information
rome 11.0.0
What happened?
.filter(
(plant) =>
!this.query?.businessIDs ||
!this.query?.businessIDs.length ||
this.query.businessIDs?.includes(plant.businessID)
)
becomes
.filter(
(plant) =>
!(this.query?.businessIDs &&this.query?.businessIDs.length ) ||
this.query.businessIDs?.includes(plant.businessID)
)
- syntax error
Expected result
It shouldn't cause a syntax error
Code of Conduct
- [X] I agree to follow Rome's Code of Conduct
another example:
if (!rows || !rows.length || !rows[0]) return []; // no results
gets fixed to
if (!((rows && rows.length) && rows[0])) return []; // no results
Which then causes useOptionalChain to flag instead, and another quick fix:
f (!(row?.lengthh && rows[0])) return []; // no results
This is obviously super broken at this point, not invalid syntax but 'lengthh' with that extra 'h' out of nowhere.
it's just too risky, I'm going to have to disable auto quick fix until I can be sure that these implementations are tighter.
@Conaclos I've found an interesting problem..
So this is a more detailed story of the problem and how to reproduce. It seems to be a problem specifically when auto fix on save is enabled.
It seems like both auto fixes 'fight' with each other, mangling the line when fix on save is used. But when each quick fix is applied one at a time, things work out better.
Try the code below with rules useSimplifiedLogicExpression and useOptionalChain turned on:
const rows = [];
if (!rows || !rows.length || !rows[0]) {
}