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
marcelofabri opened this Issue Oct 24, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@marcelofabri
Collaborator

marcelofabri commented Oct 24, 2017

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

This comment has been minimized.

Show comment
Hide comment
@jpsim

jpsim Oct 24, 2017

Collaborator

Good rule, but definitely opt-in.

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

Daniel Metzing
Introduction of Yoda condition checking.
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

Daniel Metzing
Introduction of Yoda condition checking.
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

Daniel Metzing
Introduction of Yoda condition checking.
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

Daniel Metzing
Introduction of Yoda condition checking.
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

Introduction of Yoda condition checking.
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

Daniel Metzing
Introduction of Yoda condition checking.
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

Introduction of Yoda condition checking.
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

Daniel Metzing
Introduction of Yoda condition checking.
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

Daniel Metzing
Introduction of Yoda condition checking.
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

Daniel Metzing
Introduction of Yoda condition checking.
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

Daniel Metzing
Introduction of Yoda condition checking.
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

Daniel Metzing
Introduction of Yoda condition checking.
This PR aims to implement [realm#1924][1].
[1]: realm#1924
@jpsim

This comment has been minimized.

Show comment
Hide comment
@jpsim

jpsim Dec 20, 2017

Collaborator

Done in #1965

Collaborator

jpsim commented Dec 20, 2017

Done in #1965

@jpsim jpsim closed this Dec 20, 2017

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