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

switch_case_alignment doesn't work with switch expressions #5080

Closed
2 tasks done
futuretap opened this issue Jun 26, 2023 · 4 comments · Fixed by #5086 or #5229
Closed
2 tasks done

switch_case_alignment doesn't work with switch expressions #5080

futuretap opened this issue Jun 26, 2023 · 4 comments · Fixed by #5086 or #5229
Assignees
Labels
bug Unexpected and reproducible misbehavior.

Comments

@futuretap
Copy link

futuretap commented Jun 26, 2023

New Issue Checklist

Describe the bug

A switch expression that is assigned to a variable (SE0380) throws the error

warning: Switch and Case Statement Alignment Violation: Case statements should vertically align with their enclosing switch statement (switch_case_alignment)

Complete output when running SwiftLint, including the stack trace and command used

see above

Environment

  • SwiftLint version 0.52.3
  • CocoaPods
  • No configuration file used (default CocoaPods installation)
  • Xcode version 15.0 beta 2 (15A5161b)
  • Do you have a sample that shows the issue?
// This triggers a violation:
let color: UIColor = switch state {
case [.highlighted]:
	.gray
case .selected, [.selected, .highlighted]:
	.white
case .disabled:
	.lightGray
default:
	.clear
}
@SimplyDanny
Copy link
Collaborator

SimplyDanny commented Jun 27, 2023

I've "fixed" it by disabling this rule for such cases for the time being. Would you let me know how you see this issue to be fixed properly in #5086, @futuretap?

@futuretap
Copy link
Author

That's what I did too. I'm confused about your question though. A proper fix would be that swiftlint accepts the mentioned code snippet. The vertical alignment of case and default should refer to the closing curly brace.

@SimplyDanny
Copy link
Collaborator

That's what I did too. I'm confused about your question though. A proper fix would be that swiftlint accepts the mentioned code snippet. The vertical alignment of case and default should refer to the closing curly brace.

Ah sorry ... my comment was very confusing. I mean that I prepared a PR ignoring switch expressions assigned to variables in the rule. I wonder if this is what you'd expect. The rule has a configuration which could as well be used to configure it's behavior for switch expression really used as such.

@futuretap
Copy link
Author

Thanks, this works well for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
2 participants