realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.46k stars 2.2k forks source link

Add new `prefer_key_path` rule #5548

Open SimplyDanny opened 2 months ago

SimplyDanny commented 2 months ago

This new rule triggers on code like

list.filter { $0.isValid }

which can be replaced by

list.filter(\.isValid)

as of Swift 5.2.

Automatic fixes fail once the argument label for the closure is named. The fix would need to know its name and insert it in the function call. But that's impossible for a syntax-based rule. We could do auto-fixes for simple cases like map and filter (which represent most of the findings in OSS projects and SwiftLint itself) at least. I'm not sure if partial fixes are a good thing though.

SimplyDanny commented 2 months ago

@mildm8nnered: I'd like to hear your opinion. The rule doesn't seem to be so involved. Any more cases or shortcomings you can think of?

SwiftLintBot commented 2 months ago
1983 Warnings
:warning: This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/Cache.swift:700:58: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/PoiStringProvider.swift:252:67: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/PoiStringProvider.swift:256:67: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Aerial: /Aerial/Source/Models/Sources/SourceList.swift:363:64: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Aerial: /Aerial/Source/Models/Sources/VideoList.swift:210:25: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Aerial: /Aerial/Source/Models/Sources/VideoList.swift:440:46: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Aerial: /Aerial/Source/Models/Sources/VideoList.swift:81:78: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Aerial: /Aerial/Source/Models/Sources/VideoList.swift:87:78: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Aerial: /Aerial/Source/Views/PrefPanel/InfoWeatherView.swift:208:31: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Alamofire: /Source/Features/Concurrency.swift:790:33: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Alamofire: /Source/Features/Concurrency.swift:819:33: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Alamofire: /Tests/ProtectedTests.swift:250:56: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /App/ShareExtension/ShareToBraveViewController.swift:73:19: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /App/ShareExtension/ShareToBraveViewController.swift:78:51: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /App/ShareExtension/ShareToBraveViewController.swift:78:93: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Extensions/UIViewExtensions.swift:94:58: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Playlist.swift:70:107: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/BrowserViewController/BVC+ToolbarDelegate.swift:372:107: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Widgets.swift:54:61: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift:1196:41: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift:516:48: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift:550:50: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/Playlist/Controllers/PlaylistCarplayController.swift:119:58: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/Playlist/Controllers/PlaylistCarplayController.swift:366:63: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/Playlist/Controllers/PlaylistListViewController.swift:448:47: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/Playlist/Managers & Cache/PlaylistCarplayManager.swift:93:15: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/Search/SearchEngines.swift:155:73: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/Search/SearchEngines.swift:322:128: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/Tab.swift:417:50: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/Tab.swift:417:68: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/TabManager.swift:504:40: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/Tabs/TabTray/TabTrayController+TableViewDelegate.swift:188:42: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/AddEditBookmarkTableViewController.swift:479:80: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Settings/Debug/Brave Search/BraveSearchDebugMenu.swift:78:22: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Settings/Debug/Rewards Internals/QA/RewardsDebugSettingsViewController.swift:36:96: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Settings/Features/ShieldsPrivacy/ClearDataSectionView.swift:57:88: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Settings/General/SearchEngines/SearchSettingsTableViewController.swift:83:41: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Settings/Tabs/PrivateTabsView.swift:76:58: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Settings/Tabs/PrivateTabsView.swift:77:57: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Shields/ShieldsSwitch.swift:216:39: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Shields/ShieldsSwitch.swift:220:39: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Paged/SolanaProviderScriptHandler.swift:308:68: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Sandboxed/SiteStateListenerScriptHandler.swift:113:41: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Migration/Migration.swift:61:52: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Migration/Migration.swift:77:19: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Migration/Migration.swift:83:61: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Brave/Migration/Migration.swift:87:27: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveNews/Composer/FeedDataSource.swift:79:11: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveNews/Composer/FeedDataSource.swift:843:59: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveNews/Composer/FeedDataSource.swift:884:55: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveNews/Composer/FeedDataSource.swift:89:11: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveUI/Popover/PopoverController.swift:329:35: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Chart/LineChartView.swift:262:35: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Chart/LineChartView.swift:44:33: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift:320:46: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift:353:46: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/Onboarding/RestoreWalletView.swift:62:101: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift:239:128: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift:327:52: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/Stores/PortfolioStore.swift:498:14: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/Stores/SendTokenStore.swift:299:132: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift:950:141: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/Stores/TransactionConfirmationStore.swift:282:126: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/Stores/TransactionConfirmationStore.swift:311:126: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Settings/CustomNetworkDetailsView.swift:141:31: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Settings/CustomNetworkDetailsView.swift:165:32: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Settings/CustomNetworkDetailsView.swift:189:33: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Settings/CustomNetworkDetailsView.swift:465:54: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Settings/CustomNetworkDetailsView.swift:517:66: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/WalletUserAssetManager.swift:169:88: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/WalletUserAssetManager.swift:209:33: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Data/models/PlaylistItem.swift:292:36: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Data/models/PlaylistItem.swift:294:52: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Playlist/PlaylistManager.swift:233:21: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Playlist/PlaylistManager.swift:783:67: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Sources/Shared/SystemUtils.swift:26:66: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:112:49: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:125:60: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:144:49: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:157:60: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:15:47: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:176:49: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:189:60: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:208:56: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:220:67: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:238:54: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:251:65: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:51:49: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:64:60: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:82:49: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/InitialSearchEnginesTests.swift:95:60: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/SearchEnginesTests.swift:51:60: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/SolanaProviderScriptHandlerTests.swift:243:66: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /Tests/ClientTests/SolanaProviderScriptHandlerTests.swift:280:66: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in Brave: /ThirdParty/Static/Static/DataSource.swift:172:36: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /Core/ContentBlockerRulesLists.swift:37:76: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /Core/CookieStorage.swift:138:53: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/ActionMessageView.swift:127:64: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/AutofillLoginListViewModel.swift:106:18: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/CookieDebugViewController.swift:60:47: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/DaxDialogViewController.swift:155:67: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/DaxDialogs.swift:391:63: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/DaxDialogs.swift:393:25: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/DownloadManager.swift:175:57: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/DownloadManager.swift:176:67: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/DownloadsListDataSource.swift:78:70: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/DownloadsListSectioningHelper.swift:83:81: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/FireButtonAnimator.swift:115:64: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/MainViewController.swift:153:56: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/NetworkProtectionStatusViewModel.swift:183:18: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/NetworkProtectionStatusViewModel.swift:246:63: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/NetworkProtectionVPNSettingsViewModel.swift:58:18: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/PreserveLoginsWorker.swift:38:61: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/PrivacyDashboard/PrivacyDashboardViewController.swift:352:88: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/RootDebugViewController.swift:306:18: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/Subscription/AsyncHeadlessWebview/HeadlessWebView.swift:121:103: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/TabManager.swift:273:55: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/TabPreviewsSource.swift:200:43: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/UIScrollViewExtension.swift:31:64: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/global.swift:26:49: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/BookmarkListViewModelTests.swift:110:42: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/BookmarkListViewModelTests.swift:124:36: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/BookmarkListViewModelTests.swift:138:42: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/BookmarkListViewModelTests.swift:279:54: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/BookmarkListViewModelTests.swift:279:95: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/BookmarkListViewModelTests.swift:309:54: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/BookmarkListViewModelTests.swift:309:95: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/BookmarkListViewModelTests.swift:79:32: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/BookmarkListViewModelTests.swift:89:34: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/BookmarkListViewModelTests.swift:99:36: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
:warning: Danger found 1983 violations with this PR. Due to GitHub's max issue comment size, the number shown has been truncated to 130.
17 Messages
:book: Linting Aerial with this PR took 0.89s vs 0.89s on main (0% slower)
:book: Linting Alamofire with this PR took 1.26s vs 1.23s on main (2% slower)
:book: Linting Brave with this PR took 7.33s vs 7.29s on main (0% slower)
:book: Linting DuckDuckGo with this PR took 4.08s vs 4.12s on main (0% faster)
:book: Linting Firefox with this PR took 10.45s vs 10.36s on main (0% slower)
:book: Linting Kickstarter with this PR took 9.14s vs 9.09s on main (0% slower)
:book: Linting Moya with this PR took 0.52s vs 0.51s on main (1% slower)
:book: Linting NetNewsWire with this PR took 2.5s vs 2.54s on main (1% faster)
:book: Linting Nimble with this PR took 0.74s vs 0.77s on main (3% faster)
:book: Linting PocketCasts with this PR took 8.07s vs 7.96s on main (1% slower)
:book: Linting Quick with this PR took 0.42s vs 0.42s on main (0% slower)
:book: Linting Realm with this PR took 4.62s vs 4.65s on main (0% faster)
:book: Linting Sourcery with this PR took 2.36s vs 2.36s on main (0% slower)
:book: Linting Swift with this PR took 4.45s vs 4.43s on main (0% slower)
:book: Linting VLC with this PR took 1.21s vs 1.22s on main (0% faster)
:book: Linting Wire with this PR took 17.31s vs 17.25s on main (0% slower)
:book: Linting WordPress with this PR took 12.87s vs 12.84s on main (0% slower)

Generated by :no_entry_sign: Danger

mildm8nnered commented 2 months ago

@mildm8nnered: I'd like to hear your opinion. The rule doesn't seem to be so involved. Any more cases or shortcomings you can think of?

Just trying it on my local codebase, which I expect to have a lot of violations, pretty much like the OSS findings.

mildm8nnered commented 2 months ago

@mildm8nnered: I'd like to hear your opinion. The rule doesn't seem to be so involved. Any more cases or shortcomings you can think of?

Just trying it on my local codebase, which I expect to have a lot of violations, pretty much like the OSS findings.

So most hits look good, but I think this might be a false alarm (where there is no property named otherResults). I adapted this from proprietary code that I saw the hit with - I have not tested this specific example code here, but if it doesn't get a hit I can dig in deeper on my side.

            guard let otherResults = results as? [SomeClass] else {
                return
            }

            let dictionary = Dictionary(grouping: ↓otherResults) {
                $0.someProperty
            }
SimplyDanny commented 2 months ago

@mildm8nnered: I'd like to hear your opinion. The rule doesn't seem to be so involved. Any more cases or shortcomings you can think of?

Just trying it on my local codebase, which I expect to have a lot of violations, pretty much like the OSS findings.

So most hits look good, but I think this might be a false alarm (where there is no property named otherResults). I adapted this from proprietary code that I saw the hit with - I have not tested this specific example code here, but if it doesn't get a hit I can dig in deeper on my side.

            guard let otherResults = results as? [SomeClass] else {
                return
            }

            let dictionary = Dictionary(grouping: ↓otherResults) {
                $0.someProperty
            }

The rule would complain about the closure and suggest Dictionary(grouping: otherResult, by: \.someProperty). Looks okay to me.

SimplyDanny commented 1 day ago

I'm still unsure about this rule. As we see in the list of OSS findings, there will potentially be a lot of violations in existing code bases (78 in SwiftLint), most of them on .map, .filter, ... These are cases that could be and should be (due to their sheer amount) auto-fixed. However, fixing all findings will very likely lead to wrong code due to missing parameter names for custom functions accepting closures.

Fixing only a few (but most of the) findings seems to be against the philosophy of SwiftLint. Are there other rules that fix only partially? Would this be acceptable? Or do people expect a swiftlint lint --fix run to repair all violations?