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

Add new prefer_key_path rule #5548

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SimplyDanny
Copy link
Collaborator

@SimplyDanny SimplyDanny commented Apr 29, 2024

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
Copy link
Collaborator Author

SimplyDanny commented Apr 29, 2024

@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
Copy link

SwiftLintBot commented Apr 29, 2024

2009 Warnings
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/AutofillLoginListViewModel.swift:105:18: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/MainViewController.swift:141:56: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/NetworkProtectionStatusViewModel.swift:177:18: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/NetworkProtectionStatusViewModel.swift:240:63: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
⚠️ 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)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/PrivacyDashboard/PrivacyDashboardViewController.swift:316:88: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/RemoteMessagingStore.swift:249:58: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/RootDebugViewController.swift:295:18: warning: Prefer Key Path Violation: Use a key path argument instead of a closure with property access (prefer_key_path)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ 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)
⚠️ Danger found 2009 violations with this PR. Due to GitHub's max issue comment size, the number shown has been truncated to 130.
17 Messages
📖 Linting Aerial with this PR took 1.24s vs 1.24s on main (0% slower)
📖 Linting Alamofire with this PR took 1.79s vs 1.81s on main (1% faster)
📖 Linting Brave with this PR took 10.45s vs 10.4s on main (0% slower)
📖 Linting DuckDuckGo with this PR took 5.34s vs 5.32s on main (0% slower)
📖 Linting Firefox with this PR took 13.41s vs 13.35s on main (0% slower)
📖 Linting Kickstarter with this PR took 12.7s vs 12.62s on main (0% slower)
📖 Linting Moya with this PR took 0.69s vs 0.69s on main (0% slower)
📖 Linting NetNewsWire with this PR took 3.83s vs 3.82s on main (0% slower)
📖 Linting Nimble with this PR took 1.03s vs 1.02s on main (0% slower)
📖 Linting PocketCasts with this PR took 10.32s vs 10.27s on main (0% slower)
📖 Linting Quick with this PR took 0.46s vs 0.46s on main (0% slower)
📖 Linting Realm with this PR took 6.4s vs 6.39s on main (0% slower)
📖 Linting Sourcery with this PR took 3.16s vs 3.15s on main (0% slower)
📖 Linting Swift with this PR took 6.34s vs 6.32s on main (0% slower)
📖 Linting VLC with this PR took 1.68s vs 1.68s on main (0% slower)
📖 Linting Wire with this PR took 23.61s vs 23.49s on main (0% slower)
📖 Linting WordPress with this PR took 15.67s vs 15.61s on main (0% slower)

Generated by 🚫 Danger

@mildm8nnered
Copy link
Collaborator

@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
Copy link
Collaborator

@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
Copy link
Collaborator Author

@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.

@@ -61,6 +61,11 @@
[SimplyDanny](https://github.com/SimplyDanny)
[#70](https://github.com/realm/SwiftLint/issues/70)

* Add new `prefer_key_path` rule that triggers when a trailing closure on a function
Copy link

Choose a reason for hiding this comment

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

Should it be mentioned that the rule is opt-in or disabled by default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, that's not necessary as it can be looked up in the Rule Directory.

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.

None yet

4 participants