Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no-useless-switch-case rule #1779

Merged
merged 9 commits into from Apr 1, 2022

Conversation

fisker
Copy link
Collaborator

@fisker fisker commented Mar 31, 2022

Fixes #1698.

One known issue, I only checked cases where the default case is the last case.

Because

			switch (1) {
					// This is not useless
					case 1:
					default:
							console.log('1')
					case 1:
							console.log('2')
			}
			switch (1) {
					// This is useless
					case 1:
					default:
							console.log('1')
					case 2:
							console.log('2')
			}

To handle these two cases correctly, I need to compare the conditions, and it can be difficult(event impossible if the test condition is a complex expression).

Let's keep this rule simple for now.

@fisker fisker marked this pull request as ready for review March 31, 2022 07:54
docs/rules/no-useless-switch-case.md Outdated Show resolved Hide resolved
docs/rules/no-useless-switch-case.md Outdated Show resolved Hide resolved
docs/rules/no-useless-switch-case.md Outdated Show resolved Hide resolved
rules/no-useless-switch-case.js Outdated Show resolved Hide resolved
rules/no-useless-switch-case.js Outdated Show resolved Hide resolved
rules/utils/get-switch-case-head-location.js Outdated Show resolved Hide resolved
@sindresorhus sindresorhus merged commit a8fb966 into sindresorhus:main Apr 1, 2022
@fisker fisker deleted the no-useless-switch-case branch April 1, 2022 07:24
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.

Rule proposal: no-useless-switch-case
3 participants