Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

🐛 lint/complexity/useSimplifiedLogicExpression quick fix breaks #4163

Open
1 task done
jpike88 opened this issue Jan 19, 2023 · 3 comments
Open
1 task done

🐛 lint/complexity/useSimplifiedLogicExpression quick fix breaks #4163

jpike88 opened this issue Jan 19, 2023 · 3 comments
Labels
S-To triage Status: user report of a possible bug that needs to be triaged

Comments

@jpike88
Copy link

jpike88 commented Jan 19, 2023

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

  • I agree to follow Rome's Code of Conduct
@jpike88 jpike88 added the S-To triage Status: user report of a possible bug that needs to be triaged label Jan 19, 2023
@jpike88 jpike88 changed the title 🐛 lint/complexity/useSimplifiedLogicExpression breaks with edge case 🐛 lint/complexity/useSimplifiedLogicExpression quick fix breaks with edge case Jan 19, 2023
@jpike88 jpike88 changed the title 🐛 lint/complexity/useSimplifiedLogicExpression quick fix breaks with edge case 🐛 lint/complexity/useSimplifiedLogicExpression quick fix breaks Jan 19, 2023
@jpike88
Copy link
Author

jpike88 commented Jan 24, 2023

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
Copy link
Author

jpike88 commented Jan 24, 2023

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
Copy link
Author

jpike88 commented Feb 15, 2023

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
S-To triage Status: user report of a possible bug that needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant