sindresorhus/eslint-plugin-unicorn

Rule proposal: `no-useless-else`

Open

#987 创建于 2021年1月2日

在 GitHub 查看
 (3 评论) (8 反应) (0 负责人)JavaScript (5,022 star) (468 fork)user submission
help wantednew rule

描述

If the body of if contains one of these keywords, the else is moot:

  • throw
  • break
  • continue
  • return

This slightly overlaps with https://eslint.org/docs/rules/no-else-return

This was inspired by https://github.com/eslint/eslint/issues/13067.

This could be auto-fixed, but we should take care to properly move any comments.

Fail

if (foo) {
	throw new Error();
} else {
	console.log('🦄');
}

Pass

if (foo) {
	throw new Error();
} 

console.log('🦄');

贡献者指南