-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
New Rule - Toggle Bool #2369
New Rule - Toggle Bool #2369
Conversation
CHANGELOG.md
Outdated
@@ -29,6 +29,11 @@ | |||
[Marcelo Fabri](https://github.com/marcelofabri) | |||
[#2123](https://github.com/realm/SwiftLint/issues/2123) | |||
|
|||
* Add `toggle_bool` opt-in rule which suggests using `Bool.toggle()` over | |||
`someBool = !someBool`. Requires Swift 4.2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure there are two trailing spaces on the last line describing the change. See CONTRIBUTING.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, must have missed that one. 😅
public static var description = RuleDescription( | ||
identifier: "toggle_bool", | ||
name: "Toggle Bool", | ||
description: "Prefer `Bool.toggle()` over `someBool = !someBool`.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use someBool.toggle()
instead of Bool.toggle()
to be more explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah, I think that makes more sense. I've also updated the Changelog to match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! 🎉
This PR adds a new rule for preferring
Bool.toggle()
over negation in Swift 4.2