Skip to content

Conversation

@fisker
Copy link
Collaborator

@fisker fisker commented Apr 27, 2021

Fixes #1116

@fisker fisker force-pushed the prefer-ternary-improve branch from cb1a37f to 9bbfe66 Compare April 27, 2021 09:26
fisker added a commit to fisker/eslint-plugin-unicorn that referenced this pull request Apr 27, 2021
@fisker
Copy link
Collaborator Author

fisker commented Apr 27, 2021

//cc @fregante @JounQin https://github.com/fisker/eslint-plugin-unicorn/pull/282/files I run this on our codebase, feel losing readability, look good to you?

@fregante
Copy link
Collaborator

fregante commented Apr 27, 2021

Indeed there’s an existing issue with that rule:

  • prefer-ternary should probably not apply to long lines, it tends to make them less readable

a possible improvement would be to put the condition on its own constant.

Edit: #1079 (comment)

@JounQin
Copy link
Contributor

JounQin commented Apr 27, 2021

LGTM except @fregante mentioned.

@fisker
Copy link
Collaborator Author

fisker commented Apr 27, 2021

This

if (a) {
	return 1;
}

if (b) {
	return 2;
}

if (c) {
	return 3;
} else {
	return 4;
} 

seems fine to fix to

if (a) {
	return 1;
}

if (b) {
	return 2;
}

return c ? 3 : 4;

But

if (a) {
	return 1;
}

if (b) {
	return 2;
}

if (c) {
	return 3;
}

return 4;

seems bad to fix to

if (a) {}

if (b) {}

return c ? 3 : 4

@fisker
Copy link
Collaborator Author

fisker commented Apr 27, 2021

Example this line https://github.com/fisker/eslint-plugin-unicorn/pull/282/files#diff-b6b472744fff513bca9c7577f37bc75b74371f8f7fab1621e4aae16ce15793dcL53, there are many other if above it.

@sindresorhus
Copy link
Owner

seems bad to fix to

Agreed

@sindresorhus
Copy link
Owner

Closing as this has been open for multiple years now without any activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can prefer-ternary be merged into eslint core rule no-else-return?

4 participants