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

for_where, false positive for optional binding #1838

Closed
jaywgsa opened this Issue Sep 13, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@jaywgsa

jaywgsa commented Sep 13, 2017

This for in loop with optional binding violates the rule "for_where":
for node in json {
if var data = node.value as? [String: String] {
//do stuff with data
}
}

But the rules preferred code doesn't compile:
for node in json where var data = node.value as? [String: String] {
//do stuff with data
}
Maybe I don't know how to write the correct code.
Or the rule is throwing a false positive.

Environment

SwiftLint 0.22.0 over CocoaPods
and Swift3 in Xcode 8.3.3

@marcelofabri

This comment has been minimized.

Show comment
Hide comment
@marcelofabri

marcelofabri Sep 13, 2017

Collaborator

Are you sure this example triggers? I wasn't able to reproduce it.

Also, if you check the examples you can see that it shouldn't trigger indeed.

Collaborator

marcelofabri commented Sep 13, 2017

Are you sure this example triggers? I wasn't able to reproduce it.

Also, if you check the examples you can see that it shouldn't trigger indeed.

@jaywgsa

This comment has been minimized.

Show comment
Hide comment
@jaywgsa

jaywgsa Sep 14, 2017

You are right, this example actually doesn't trigger. I was trying to explain the false positive with an standard "if let" optional binding. Sorry about that.
My real code is an "if var" and that does trigger a false positive. I have edited the issue.

jaywgsa commented Sep 14, 2017

You are right, this example actually doesn't trigger. I was trying to explain the false positive with an standard "if let" optional binding. Sorry about that.
My real code is an "if var" and that does trigger a false positive. I have edited the issue.

@marcelofabri marcelofabri added bug and removed repro-needed labels Sep 14, 2017

marcelofabri added a commit to marcelofabri/SwiftLint that referenced this issue Sep 14, 2017

@marcelofabri

This comment has been minimized.

Show comment
Hide comment
@marcelofabri

marcelofabri Sep 14, 2017

Collaborator

Thanks for the update, @jaylindelycke! I've submitted #1840 to fix the issue.

Collaborator

marcelofabri commented Sep 14, 2017

Thanks for the update, @jaylindelycke! I've submitted #1840 to fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment