tools icon indicating copy to clipboard operation
tools copied to clipboard

🐛 `lint/complexity/useSimplifiedLogicExpression` quick fix breaks

Open jpike88 opened this issue 2 years ago • 3 comments

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

jpike88 avatar Jan 19 '23 17:01 jpike88

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.

jpike88 avatar Jan 24 '23 09:01 jpike88

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.

jpike88 avatar Jan 24 '23 09:01 jpike88

@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]) {
			}

jpike88 avatar Feb 15 '23 05:02 jpike88