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

New Rule - Toggle Bool #2369

Merged
merged 7 commits into from
Aug 30, 2018
Merged

Conversation

daltonclaybrook
Copy link
Contributor

This PR adds a new rule for preferring Bool.toggle() over negation in Swift 4.2

@SwiftLintBot
Copy link

SwiftLintBot commented Aug 30, 2018

25 Warnings
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/BackForwardListViewController.swift:146:13: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/QRCodeViewController.swift:203:9: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/Tab.swift:483:9: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/TabTrayController.swift:280:9: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/TabTrayController.swift:282:9: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Settings/AppSettingsOptions.swift:607:13: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Widgets/PhotonActionSheet.swift:294:13: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in Swift: /Users/distiller/project/osscheck/Swift/stdlib/public/core/Bool.swift:347:5: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in Swift: /Users/distiller/project/osscheck/Swift/stdlib/public/SDK/Foundation/IndexSet.swift:735:17: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in Swift: /Users/distiller/project/osscheck/Swift/stdlib/public/SDK/Foundation/IndexSet.swift:737:13: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in Swift: /Users/distiller/project/osscheck/Swift/stdlib/public/SDK/Foundation/IndexSet.swift:742:13: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/Models/Notifications/Actions/ApproveComment.swift:79:9: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Blog/SharingButtonsViewController.swift:395:21: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Blog/SharingButtonsViewController.swift:439:21: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Cells/ExpandableCell.swift:53:9: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Media/MediaLibraryViewController.swift:261:9: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationSettingsViewController.swift:409:13: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationSettingsViewController.swift:412:13: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockActionsTableViewCell.swift:244:13: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockActionsTableViewCell.swift:259:13: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift:91:13: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Plugins/PluginViewModel.swift:346:17: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Plugins/PluginViewModel.swift:362:17: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Plugins/PluginViewModel.swift:378:17: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/ViewRelated/Plugins/PluginViewModel.swift:394:17: warning: Toggle Bool Violation: Prefer someBool.toggle() over someBool = !someBool. (toggle_bool)
12 Messages
📖 Linting Aerial with this PR took 0.53s vs 0.39s on master (35% slower)
📖 Linting Alamofire with this PR took 3.86s vs 3.46s on master (11% slower)
📖 Linting Firefox with this PR took 14.38s vs 12.93s on master (11% slower)
📖 Linting Kickstarter with this PR took 23.45s vs 18.65s on master (25% slower)
📖 Linting Moya with this PR took 2.8s vs 2.02s on master (38% slower)
📖 Linting Nimble with this PR took 2.65s vs 1.81s on master (46% slower)
📖 Linting Quick with this PR took 0.75s vs 0.54s on master (38% slower)
📖 Linting Realm with this PR took 3.98s vs 3.36s on master (18% slower)
📖 Linting SourceKitten with this PR took 1.23s vs 1.07s on master (14% slower)
📖 Linting Sourcery with this PR took 5.42s vs 4.67s on master (16% slower)
📖 Linting Swift with this PR took 30.98s vs 28.03s on master (10% slower)
📖 Linting WordPress with this PR took 22.19s vs 18.25s on master (21% slower)

Generated by 🚫 Danger

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.
Copy link
Contributor

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

Copy link
Contributor Author

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`.",
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

@marcelofabri marcelofabri left a 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! 🎉

@marcelofabri marcelofabri merged commit 523feae into realm:master Aug 30, 2018
@Jeehut Jeehut mentioned this pull request Sep 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants