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

Rule Request: Use where in loop instead of if #1228

Closed
kimdv opened this issue Jan 22, 2017 · 3 comments
Closed

Rule Request: Use where in loop instead of if #1228

kimdv opened this issue Jan 22, 2017 · 3 comments
Labels
rule-request Requests for a new rules.

Comments

@kimdv
Copy link
Contributor

kimdv commented Jan 22, 2017

For better readable code in my opinion it would be nice with a where rule for loops like.

I think it will make it more readable and there is less lines. Of course if there is multiple if or and if else it should be ignored

for user in users where user.id == "1" {
// Awesome code
}

instead of

for user in users {
    if user.id == "1" {
        // Awesome code
   }
}
@marcelofabri marcelofabri added the rule-request Requests for a new rules. label Jan 22, 2017
@jpsim jpsim closed this as completed in f0c8fba Feb 9, 2017
@abagmut
Copy link

abagmut commented Mar 25, 2017

get false positive for:

var name = ""
for (index, value) in lines.enumerated()
{
	if index > 0
	{
		name += ", "
	}
	name += value
}

@marcelofabri
Copy link
Collaborator

There's already an open issue for that, as well as a PR.

@Coeur
Copy link

Coeur commented Mar 29, 2017

For reference:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule-request Requests for a new rules.
Projects
None yet
Development

No branches or pull requests

4 participants