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_on_newline should support where in a new line #1268

Closed
nekrich opened this issue Feb 1, 2017 · 4 comments
Closed

switch_case_on_newline should support where in a new line #1268

nekrich opened this issue Feb 1, 2017 · 4 comments
Labels

Comments

@nekrich
Copy link

nekrich commented Feb 1, 2017

Example:

enum SampleError: Error, Equatable {
	
	case boom
	case bang
	case ouch
	case badaboom(code: Int, description: String)
	
	static func == (lhs: SampleError, rhs: SampleError) -> Bool {
		
		switch (lhs, rhs) {
			
		case let (.badaboom(code: lhsErrorCode, description: _), .badaboom(code: rhsErrorCode, description: _))
			where lhsErrorCode == rhsErrorCode:
			
			return true
			
		case (.boom, .boom),
		     (.bang, .bang), (.ouch, .ouch):
			
			return true
			
		default:
			
			return false
			
		}
		
	}
	
}
  1. false positive in first case - case let (.badaboom(....
  2. no warning on the second line of second case: (.bang, .bang), (.ouch, .ouch):.

swiftlint version: 0.16.1

@marcelofabri
Copy link
Collaborator

I could reproduce 1, but I'm not sure what you mean with 2. It seems to be the expected behavior. 🤔

@marcelofabri
Copy link
Collaborator

BTW, I don't think the issue is about enum with tuples, but breaking the case in 2 lines when using where.

@nekrich
Copy link
Author

nekrich commented Feb 1, 2017

I think, that is my fail in understanding that rule.
I just prefer:
a) to group list of values in one case statement where it acceptable and in this case to write each pattern from a new line.
b) and write where conditions from a new line (not only in switch statement).

@nekrich nekrich closed this as completed Feb 1, 2017
@marcelofabri
Copy link
Collaborator

I'll reopen since I think we should support 1 anyway.

Just to be clear: the rule only validates that the body of a case is in a new line.

@marcelofabri marcelofabri reopened this Feb 1, 2017
@marcelofabri marcelofabri changed the title switch_case_on_newline: wrong behavior on enum with tuples. switch_case_on_newline should support where in a new line Feb 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants