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: Avoid Yoda conditions #1924

Closed
2 tasks done
marcelofabri opened this issue Oct 24, 2017 · 2 comments
Closed
2 tasks done

Rule request: Avoid Yoda conditions #1924

marcelofabri opened this issue Oct 24, 2017 · 2 comments

Comments

@marcelofabri
Copy link
Collaborator

New Issue Checklist

Rule Request

  1. Why should this rule be added? Share links to existing discussion about what
    the community thinks about this.

In Swift, you need a var or let keyword to do an assignment inside a condition (if, guard, etc).
Thus, you only get the disadvantages of Yoda conditions, but no benefits.

  1. Provide several examples of what would and wouldn't trigger violations.
// should trigger
if 42 == foo {}
guard "str" == bar else { return }
while 10 == baz { }

// shouldn't trigger
if foo == 42 {}
guard bar == "str" else { return }
while baz == 10 { }
if foo == bar {}
  1. Should the rule be configurable, if so what parameters should be configurable?

Just the severity.

  1. Should the rule be opt-in or enabled by default? Why?
    See README.md for guidelines on when to mark a
    rule as opt-in.

I think this might cause some false positives, so I'd say opt-in. But it could be enabled by default if we can avoid those false positives.

@jpsim
Copy link
Collaborator

jpsim commented Oct 24, 2017

Good rule, but definitely opt-in.

dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Dec 2, 2017
This PR aims to implement [realm#1924][1].
[1]: realm#1924
dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Dec 2, 2017
This PR aims to implement [realm#1924][1].
[1]: realm#1924
dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Dec 3, 2017
This PR aims to implement [realm#1924][1].
[1]: realm#1924
dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Dec 18, 2017
This PR aims to implement [realm#1924][1].
[1]: realm#1924
dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Dec 18, 2017
This PR aims to implement [realm#1924][1].
[1]: realm#1924 (+1 squashed commit)
Squashed commits:
[b6a5af92] Updates changelog entry

Moves entry to new section.
dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Dec 18, 2017
This PR aims to implement [realm#1924][1].
[1]: realm#1924
dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Dec 18, 2017
This PR aims to implement [realm#1924][1].
[1]: realm#1924 (+1 squashed commit)
Squashed commits:
[b6a5af92] Updates changelog entry

Moves entry to new section.
dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Dec 18, 2017
This PR aims to implement [realm#1924][1].
[1]: realm#1924
dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Dec 18, 2017
This PR aims to implement [realm#1924][1].
[1]: realm#1924
dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Dec 18, 2017
This PR aims to implement [realm#1924][1].
[1]: realm#1924
dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Dec 18, 2017
This PR aims to implement [realm#1924][1].
[1]: realm#1924
dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this issue Dec 18, 2017
This PR aims to implement [realm#1924][1].
[1]: realm#1924
@jpsim
Copy link
Collaborator

jpsim commented Dec 20, 2017

Done in #1965

@jpsim jpsim closed this as completed Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants