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

Improve for_where rule #1387

Closed
marcelofabri opened this issue Mar 24, 2017 · 6 comments
Closed

Improve for_where rule #1387

marcelofabri opened this issue Mar 24, 2017 · 6 comments
Labels
enhancement Ideas for improvements of existing features and rules.

Comments

@marcelofabri
Copy link
Collaborator

If the if is too complex, it's better to have it instead of a where clause.

Also, that bug that prevents us to recognize local variables sometimes makes the rule trigger false positives.

@marcelofabri marcelofabri added the enhancement Ideas for improvements of existing features and rules. label Mar 24, 2017
@keith
Copy link
Collaborator

keith commented Mar 27, 2017

I found a false positive for this rule as well:

for a in [1, 2, 3] {
    if a == 1 {
        return 0
    }

    return a
}

Here the a == 1 could not be added as a where since we still want to do something in the alternate case. A simple workaround for now:

for a in [1, 2, 3] {
    if a == 1 {
        return 0
    } else {
        return a
    }
}

@marcelofabri
Copy link
Collaborator Author

@keith Could you try running with #1393? I think that should fix the issue as well

@keith
Copy link
Collaborator

keith commented Mar 27, 2017

Trying!

@keith
Copy link
Collaborator

keith commented Mar 27, 2017

Confirmed! Thanks you beat me to it!!

@eaigner
Copy link
Contributor

eaigner commented Feb 8, 2019

Another false positive

screen shot 2019-02-08 at 13 15 09

This rule should not apply if the if block returns.

@jpsim
Copy link
Collaborator

jpsim commented Feb 10, 2019

That's not a false positive, these are all equivalent:

private var allFilesExpanded: Bool {
    for index in visibleFileRowIndexes {
        if !visibleParts[index].isExpanded {
            return false
        }
    }
    return true
}
private var allFilesExpanded: Bool {
    for index in visibleFileRowIndexes where !visibleParts[index].isExpanded {
        return false
    }
    return true
}

and finally:

private var allFilesExpanded: Bool {
    return visibleFileRowIndexes.allSatisfy { visibleParts[$0].isExpanded }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Ideas for improvements of existing features and rules.
Projects
None yet
Development

No branches or pull requests

4 participants