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

Adds opt-in rule discouraged_optional_collection #2001

Merged
merged 15 commits into from
Mar 27, 2018

Conversation

ornithocoder
Copy link
Contributor

@ornithocoder ornithocoder commented Jan 10, 2018

Implements #1885.

I tried to use regular expressions to match collections, but soon realized I would need recursion support - ?R - to find and match nested collections, something Foundation doesn't offer.

So I decided to re-implement the rule as an ASTRule, looking for balanced optional collections in functions and variables declarations.

Example: [String: [Int]?]

[  S  t  r  i  n  g  :     [  I  n  t  ]  ?  ]
0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15
                           ^              ^
// [9, 14]

Example: [String: [Int]?]?

[  S  t  r  i  n  g  :     [  I  n  t  ]  ?  ]  ?
0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16
^                          ^              ^     ^

// [0, 16], [9, 14]

Example: var x = Set<Int>?

v  a  r     x     =     S  e  t  <  I  n  t  >  ?
0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16
                        ^                       ^
// [8, 16]

I've added similar examples to the private String extension used by the rule to illustrate the code.

@SwiftLintBot
Copy link

SwiftLintBot commented Jan 10, 2018

352 Warnings
⚠️ Big PR
⚠️ This PR introduced a violation in Aerial: /Users/distiller/project/osscheck/Aerial/Aerial/Source/Controllers/PreferencesWindowController.swift:57:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Aerial: /Users/distiller/project/osscheck/Aerial/Aerial/Source/Controllers/PreferencesWindowController.swift:473:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Alamofire: /Users/distiller/project/osscheck/Alamofire/Example/Source/AppDelegate.swift:36:9: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Alamofire: /Users/distiller/project/osscheck/Alamofire/Source/AFError.swift:222:12: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Alamofire: /Users/distiller/project/osscheck/Alamofire/Source/AFError.swift:299:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Account/FirefoxAccount.swift:40:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Account/FirefoxAccount.swift:64:145: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Account/FirefoxAccount.swift:68:133: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Account/FirefoxAccount.swift:111:33: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Account/SyncAuthState.swift:25:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Account/SyncAuthState.swift:62:12: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Application/AdjustIntegration.swift:131:58: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Application/QuickActions.swift:29:55: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Application/QuickActions.swift:105:69: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Application/TestAppDelegate.swift:64:61: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Application/TestAppDelegate.swift:106:61: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Application/LeanplumIntegration.swift:186:32: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Application/AppDelegate.swift:38:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Application/AppDelegate.swift:42:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Application/AppDelegate.swift:45:71: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Application/AppDelegate.swift:81:88: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Application/AppDelegate.swift:208:52: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Application/AppDelegate.swift:437:91: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/BrowserViewController/BrowserViewController+KeyCommands.swift:105:14: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/FormPostHelper.swift:46:32: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/SearchSuggestClient.swift:37:33: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/TabLocationView.swift:257:14: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/TabLocationView.swift:347:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/TabLocationView.swift:426:14: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/Tab.swift:264:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/Tab.swift:268:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/Tab.swift:444:78: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/TabScrollController.swift:124:78: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/TabTrayController+KeyCommands.swift:9:14: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/TopTabsLayout.swift:90:19: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/TabManager.swift:87:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/TabManager.swift:687:17: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/TopTabsViewController.swift:93:17: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/TopTabsViewController.swift:545:25: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/ContentBlocker/ContentBlockerHelper+Whitelist.swift:94:17: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/BrowserViewController.swift:445:25: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/BrowserViewController.swift:841:78: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/BrowserViewController.swift:1402:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/URLBarView.swift:547:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Browser/URLBarView.swift:606:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/ContentBlocker/TrackingProtectionPageStats.swift:108:9: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/ContentBlocker/TrackingProtectionPageStats.swift:111:90: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/ActivityStreamTopSitesCell.swift:337:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/ActivityStreamTopSitesCell.swift:428:19: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/BookmarksPanel.swift:387:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/BookmarksPanel.swift:457:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/HistoryPanel.swift:536:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/HistoryPanel.swift:559:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/HomePanelViewController.swift:330:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/RecentlyClosedTabsPanel.swift:175:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/ActivityStreamPanel.swift:737:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/ReaderPanel.swift:190:17: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/ReaderPanel.swift:375:19: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/ReaderPanel.swift:450:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Home/RemoteTabsPanel.swift:608:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Login Management/LoginListViewController.swift:432:22: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Login Management/LoginListViewController.swift:466:16: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Widgets/AutocompleteTextField.swift:84:14: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Widgets/TwoLineCell.swift:93:35: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Widgets/TwoLineCell.swift:163:35: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Frontend/Widgets/TwoLineCell.swift:251:35: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Telemetry/UnifiedTelemetry.swift:131:122: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Client/Telemetry/UnifiedTelemetry.swift:135:125: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Providers/NSUserDefaultsPrefs.swift:108:15: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Providers/SyncStatusResolver.swift:15:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/ReadingList/ReadingListResponse.swift:12:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/ReadingList/ReadingListRecordsResponse.swift:19:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/ReadingList/ReadingListServerRecord.swift:18:11: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Providers/Profile.swift:1079:14: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Shared/Extensions/SetExtensions.swift:8:19: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Shared/Functions.swift:72:41: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Shared/Functions.swift:72:54: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Shared/Functions.swift:162:49: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Shared/Functions.swift:162:65: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Shared/Functions.swift:219:28: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Shared/Functions.swift:219:13: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Shared/Prefs.swift:150:15: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Shared/SentryIntegration.swift:98:84: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Shared/SentryIntegration.swift:108:100: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Shared/SentryIntegration.swift:129:114: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Shared/SentryIntegration.swift:156:48: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Storage/Clients.swift:18:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Storage/Bookmarks/Trees.swift:39:12: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Storage/Bookmarks/Bookmarks.swift:254:12: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Storage/Bookmarks/Bookmarks.swift:344:36: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Storage/SQL/SQLiteBookmarksModel.swift:77:64: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Storage/SQL/SQLiteBookmarksModel.swift:249:61: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Storage/SQL/SQLiteBookmarksModel.swift:308:74: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/BookmarkTelemetryPing.swift:34:73: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/BookmarkTelemetryPing.swift:34:106: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/Info.swift:43:46: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/BookmarkPayload.swift:22:32: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/State.swift:203:9: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/State.swift:357:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/State.swift:381:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/Synchronizers/Bookmarks/Merging.swift:192:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/StorageClient.swift:684:70: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/StorageClient.swift:714:75: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/SyncMeta.swift:64:36: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/SyncMeta.swift:64:24: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/SyncTelemetry/SyncTelemetryEvents.swift:27:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/SyncTelemetry/SyncTelemetryEvents.swift:33:17: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/SyncTelemetry/SyncTelemetryEvents.swift:48:10: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/Synchronizers/Bookmarks/ThreeWayTreeMerger.swift:294:14: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/Synchronizers/Bookmarks/ThreeWayTreeMerger.swift:326:14: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/Synchronizers/Bookmarks/ThreeWayTreeMerger.swift:798:58: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/SyncStateMachine.swift:45:75: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/SyncStateMachine.swift:71:97: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Sync/SyncStateMachine.swift:76:30: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Kickstarter: /Users/distiller/project/osscheck/Kickstarter/Kickstarter-iOS/DataSources/DiscoveryFiltersDataSource.swift:69:17: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Kickstarter: /Users/distiller/project/osscheck/Kickstarter/Kickstarter-iOS/AppDelegate.swift:31:5: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Kickstarter: /Users/distiller/project/osscheck/Kickstarter/Kickstarter-iOS/AppDelegate.swift:227:20: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Kickstarter: /Users/distiller/project/osscheck/Kickstarter/Kickstarter-iOS/DataSources/ProjectNavigatorPagesDataSource.swift:11:24: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ This PR introduced a violation in Kickstarter: /Users/distiller/project/osscheck/Kickstarter/Kickstarter-iOS/ViewModels/AppDelegateViewModel.swift:36:67: warning: Discouraged Optional Collection Violation: Prefer empty collection over optional collection. (discouraged_optional_collection)
⚠️ Danger found 352 violations with this PR. Due to GitHub's max issue comment size, the number shown has been truncated to 120.
12 Messages
📖 Linting Aerial with this PR took 0.44s vs 0.41s on master (7% slower)
📖 Linting Alamofire with this PR took 3.69s vs 3.53s on master (4% slower)
📖 Linting Firefox with this PR took 14.5s vs 13.83s on master (4% slower)
📖 Linting Kickstarter with this PR took 22.28s vs 21.41s on master (4% slower)
📖 Linting Moya with this PR took 2.12s vs 2.05s on master (3% slower)
📖 Linting Nimble with this PR took 2.12s vs 2.0s on master (6% slower)
📖 Linting Quick with this PR took 0.62s vs 0.58s on master (6% slower)
📖 Linting Realm with this PR took 4.07s vs 3.82s on master (6% slower)
📖 Linting SourceKitten with this PR took 1.27s vs 1.21s on master (4% slower)
📖 Linting Sourcery with this PR took 5.39s vs 5.15s on master (4% slower)
📖 Linting Swift with this PR took 17.61s vs 17.07s on master (3% slower)
📖 Linting WordPress with this PR took 18.17s vs 17.24s on master (5% slower)

Generated by 🚫 Danger

@codecov-io
Copy link

codecov-io commented Jan 10, 2018

Codecov Report

Merging #2001 into master will increase coverage by 0.03%.
The diff coverage is 98.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2001      +/-   ##
==========================================
+ Coverage   89.81%   89.85%   +0.03%     
==========================================
  Files         264      266       +2     
  Lines       15275    15362      +87     
  Branches      997     1012      +15     
==========================================
+ Hits        13719    13803      +84     
- Misses       1537     1539       +2     
- Partials       19       20       +1
Impacted Files Coverage Δ
Tests/SwiftLintFrameworkTests/RulesTests.swift 100% <100%> (ø) ⬆️
...es/DiscouragedOptionalCollectionRuleExamples.swift 100% <100%> (ø)
...work/Rules/DiscouragedOptionalCollectionRule.swift 98.76% <98.76%> (ø)
Source/SwiftLintFramework/Models/Command.swift 95.65% <0%> (-2.18%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 941a548...90d6399. Read the comment docs.

CHANGELOG.md Outdated

#### Enhancements

* Adds `discouraged_optional_collection` opt-in rule to encourages the return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/encourages the return/encourage the use/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @jpsim!

I'll have to refactor/rewrite this rule. There are some cases that are really hard to cover using regular expression. For instance:

fun foo(param: [String: [String: String]?])

vs.

fun foo(param: [String: [String: String]]?)

But thanks, I'll update the changelog entry.

@ornithocoder ornithocoder force-pushed the optional_collection branch 3 times, most recently from 64aace1 to 19c01bb Compare January 14, 2018 22:26
@ornithocoder ornithocoder changed the title [WIP] Adds opt-in rule discouraged_optional_collection Adds opt-in rule discouraged_optional_collection Jan 15, 2018
@ornithocoder ornithocoder force-pushed the optional_collection branch 2 times, most recently from afd92a5 to a9c2a44 Compare February 16, 2018 23:14
@ornithocoder
Copy link
Contributor Author

ornithocoder commented Feb 19, 2018

Hi @marcelofabri / @jpsim. Did you have a chance to look into this one? I added comments to the code to illustrate it better; for "developers of the future" that might need to interact with the code. Thanks!

@ornithocoder
Copy link
Contributor Author

ornithocoder commented Feb 21, 2018

I created a gist with the String extension (w/ examples) from this rule. It can be copied and pasted on a Playground.

@ornithocoder ornithocoder force-pushed the optional_collection branch 2 times, most recently from f8ae195 to 21be5ba Compare March 14, 2018 10:41
@ornithocoder
Copy link
Contributor Author

Hi @marcelofabri, I am sorry to bother you with this but can you take a look on this PR? I've been using it on my project at work for weeks now and it seems solid. I'd love to see it merged into SwiftLint's master. Thanks!

@marcelofabri marcelofabri merged commit 0982045 into realm:master Mar 27, 2018
@marcelofabri
Copy link
Collaborator

Thanks @ornithocoder 💯

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.

5 participants