Skip to content

prefer-ternary: interaction with no-else-return #2609

@geoffswift

Description

@geoffswift

Description

So unicorn/prefer-ternary does not play nicely with the standard rule no-else-return.

With this example

// ❌
function example() {
	if (test) {
		return a;
	} else {
		return b;
	}
}

no-else-return autofixes it like so...

// ❌
function example() {
	if (test) {
		return a;
	} 
	return b;
}

Examples

So ideally unicorn/prefer-ternary would autofix as per this example...

// ❌
function example() {
	if (test) {
		return a;
	} 
	return b;
}

// ✅
function example() {
	return test ? a : b;
}

Additional Info

Maybe having no-else-return isn't that great, but still an opportunity to improve here.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions