Skip to content

Latest commit

 

History

History
64 lines (54 loc) · 742 Bytes

no-lonely-if.md

File metadata and controls

64 lines (54 loc) · 742 Bytes

Disallow if statements as the only statement in if blocks without else

This rule adds onto the built-in no-lonely-if rule, which only forbids if statements in else, not in if.

This rule is fixable.

Fail

if (foo) {
	if (bar) {
		// …
	}
}
if (foo) {
	// …
} else if (bar) {
	if (baz) {
		// …
	}
}

Pass

if (foo && bar) {
	// …
}
if (foo) {
	// …
} else if (bar && baz) {
	// …
}
if (foo) {
	// …
} else if (bar) {
	if (baz) {
		// …
	}
} else {
	// …
}
// Built-in rule `no-lonely-if` case https://eslint.org/docs/rules/no-lonely-if
if (foo) {
	// …
} else {
	if (bar) {
		// …
	}
}