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 consider_default_literal_types_redundant option to RedundantTypeAnnotationRule #4756

Merged

Conversation

garricn
Copy link
Contributor

@garricn garricn commented Feb 8, 2023

  • Add consider_default_literal_types_redundant option to RedundantTypeAnnotationConfiguration
  • Add examples in rule description
  • Improve control flow in visitPost methods
  • Refactor isRedundant method to include and use considerLiteralsRedundant for Bool, Double, Int and String

By default, literals for Bool, Double, Int and String will be considered not redundant. For example: var isEnabled: Bool = true. This is an intentional change in behavior. See the comments below for additional details.

Important

The consider_default_literal_types_redundant option must be set to true to maintain the previous behavior.

@SwiftLintBot
Copy link

SwiftLintBot commented Feb 8, 2023

1515 Messages
📖 Linting Aerial with this PR took 0.79s vs 0.81s on main (2% faster)
📖 Linting Alamofire with this PR took 1.13s vs 1.13s on main (0% slower)
📖 Linting Brave with this PR took 6.52s vs 6.55s on main (0% faster)
📖 Linting DuckDuckGo with this PR took 3.37s vs 3.47s on main (2% faster)
📖 Linting Firefox with this PR took 9.26s vs 9.34s on main (0% faster)
📖 Linting Kickstarter with this PR took 8.33s vs 8.3s on main (0% slower)
📖 Linting Moya with this PR took 0.48s vs 0.47s on main (2% slower)
📖 Linting NetNewsWire with this PR took 2.3s vs 2.33s on main (1% faster)
📖 Linting Nimble with this PR took 0.66s vs 0.69s on main (4% faster)
📖 Linting PocketCasts with this PR took 6.95s vs 7.02s on main (0% faster)
📖 Linting Quick with this PR took 0.32s vs 0.33s on main (3% faster)
📖 Linting Realm with this PR took 4.19s vs 4.04s on main (3% slower)
📖 Linting Sourcery with this PR took 2.04s vs 2.03s on main (0% slower)
📖 Linting Swift with this PR took 3.92s vs 3.92s on main (0% slower)
📖 Linting VLC with this PR took 1.08s vs 1.09s on main (0% faster)
📖 Linting Wire with this PR took 14.34s vs 14.25s on main (0% slower)
📖 Linting WordPress with this PR took 9.83s vs 9.7s on main (1% slower)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Models/Cache/VideoDownload.swift:178:20: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Models/Cache/VideoDownload.swift:22:34: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Views/AerialView.swift:97:40: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Views/AerialView.swift:99:27: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Brave Rewards/Panel/BraveRewardsViewController.swift:144:31: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/BackForwardListAnimator.swift:9:17: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/BackForwardListViewController.swift:61:22: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/BackForwardTableViewCell.swift:47:24: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/BrowserPrompts.swift:20:18: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Menu.swift:253:41: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift:136:34: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift:196:39: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift:804:36: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageFeedOverlayView.swift:110:16: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/New Tab Page/Sections/StatsSectionProvider.swift:176:24: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Playlist/Browser/PlaylistChangeFoldersView.swift:31:39: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Playlist/Onboarding & Toast/PlaylistToast.swift:53:21: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/PrivacyHub/PrivacyReportsView.swift:22:39: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/PrivacyHub/PrivacyReportsView.swift:24:41: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Search/OpenSearchEngineButton.swift:43:32: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Search/Recent Search/RecentSearchQRCodeScannerController.swift:15:22: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Search/SearchViewController.swift:67:23: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Tab.swift:134:26: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Tab.swift:176:16: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Tab.swift:210:25: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Tab.swift:233:16: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Tab.swift:86:21: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Tabs/RecentlyClosedTabs/RecentlyClosedTabsView.swift:20:41: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Tabs/TabTray/TabTrayController.swift:86:31: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/ToolbarVisibilityViewModel.swift:74:16: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift:73:36: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/AddEditBookmarkTableViewController.swift:64:24: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/PlaylistMenuButton.swift:86:23: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/VPNMenuButton.swift:34:36: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/HeaderContainerView.swift:20:23: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/UrlBar/CollapsedURLBarView.swift:107:24: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/UrlBar/CollapsedURLBarView.swift:45:23: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift:502:28: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift:58:14: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift:72:30: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Login/LoginInfoTableViewCell.swift:44:35: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Login/LoginInfoTableViewCell.swift:50:25: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Login/LoginInfoViewController.swift:56:33: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Passcode/WindowProtection.swift:115:20: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Passcode/WindowProtection.swift:94:24: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Rewards/BraveRewards.swift:144:38: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Settings/Debug/BraveTalkLogsView.swift:13:31: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Settings/Debug/BraveTalkLogsView.swift:14:36: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Settings/Debug/Rewards Internals/RewardsInternalsShareController.swift:246:24: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Settings/Debug/SandboxInspectorView.swift:26:31: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Settings/Features/ShieldsPrivacy/ManageWebsiteDataView.swift:13:31: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Settings/Features/ShieldsPrivacy/PrivacyReportSettingsView.swift:16:41: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Settings/General/SearchEngines/SearchEnginePicker.swift:14:25: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Settings/SettingsContentViewController.swift:23:15: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Settings/SettingsContentViewController.swift:38:26: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Shields/AdvancedControlsBarView.swift:12:32: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Shields/ShieldsSwitch.swift:23:20: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Sync/SyncSelectDeviceTypeViewController.swift:17:14: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Widgets/AutocompleteTextField.swift:33:25: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Widgets/LoadingViewController.swift:21:16: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Widgets/TwoLineCell.swift:203:20: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/Brave/WebFilters/FilterList.swift:47:16: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveNews/Composer/FeedCardGenerator.swift:94:38: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveNews/Composer/FeedCardGenerator.swift:95:39: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveNews/Customize/FollowToggle.swift:65:28: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveNews/Customize/NewsSettingsView.swift:135:41: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveNews/Customize/NewsSettingsView.swift:32:32: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveNews/Customize/NewsSettingsView.swift:346:27: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveNews/Customize/OptInView.swift:17:31: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveTalk/BraveTalkJitsiCoordinator.swift:53:22: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveTalk/BraveTalkJitsiCoordinator.swift:54:47: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveTalk/BraveTalkJitsiCoordinator.swift:55:39: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/Buttons/BraveButton.swift:115:27: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/Buttons/BraveButton.swift:30:21: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/Buttons/LoaderView.swift:135:30: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/Buttons/LoaderView.swift:63:38: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/SwiftUI/AlertOnScreenshotViewModifier.swift:11:39: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/SwiftUI/CustomPrivacySensitiveModifier.swift:14:36: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/SwiftUI/CustomPrivacySensitiveModifier.swift:15:32: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/SwiftUI/ListInitialOffsetWorkaround.swift:11:34: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/SwiftUI/LottieAnimationView.swift:37:18: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/SwiftUI/NoCaptureViewModifier.swift:10:32: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/SwiftUI/Shimmer.swift:68:36: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/UIKit/UIKitPopupView.swift:115:23: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/UIKit/UIKitPopupView.swift:117:25: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveUI/UIKit/UIKitPopupView.swift:118:37: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveVPN/BraveVPN.swift:358:24: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveVPN/BraveVPN.swift:359:25: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveVPN/BraveVPNPickerViewController.swift:30:16: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveVPN/BraveVPNSettingsViewController.swift:50:24: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveVPN/BuyVPNViewController.swift:269:16: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Accounts/AccountSelectionView.swift:17:44: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Accounts/Activity/AccountActivityView.swift:20:29: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Accounts/Activity/AccountActivityView.swift:21:45: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Accounts/Activity/AccountActivityView.swift:22:47: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Accounts/Add/AddAccountView.swift:17:40: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Accounts/Add/AddAccountView.swift:18:35: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Accounts/Add/AddAccountView.swift:20:36: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Accounts/Details/AccountDetailsView.swift:23:36: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Accounts/Details/AccountDetailsView.swift:24:52: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Asset Details/AssetDetailView.swift:24:48: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Asset Details/AssetDetailView.swift:25:44: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Asset Details/AssetDetailView.swift:26:56: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Asset Details/AssetDetailView.swift:28:46: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/Asset Details/AssetDetailView.swift:43:48: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/AssetIconView.swift:136:28: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/AssetIconView.swift:138:24: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/AssetIconView.swift:63:28: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/BuySendSwap/AccountPicker.swift:14:40: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/BuySendSwap/SendTokenView.swift:21:53: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/BuySendSwap/SwapCryptoView.swift:171:45: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/CryptoTabsView.swift:37:39: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/CryptoTabsView.swift:39:37: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/CryptoTabsView.swift:40:37: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/CryptoTabsView.swift:41:41: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/CryptoTabsView.swift:42:55: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift:139:45: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/NFT/NFTDetailView.swift:23:45: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/NFT/NFTView.swift:20:48: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/NFT/NFTView.swift:21:43: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/NFTImageView.swift:68:14: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
📖 This PR fixed a violation in Brave: /Sources/BraveWallet/Crypto/NetworkPicker.swift:27:44: warning: Redundant Type Annotation Violation: Variables should not have redundant type annotation (redundant_type_annotation)
⚠️ Danger found 1515 violations with this PR. Due to GitHub's max issue comment size, the number shown has been truncated to 139.

Generated by 🚫 Danger

@garricn garricn force-pushed the add-redundant-type-annotation-configuration branch from 70ebae1 to 2cd28bd Compare February 8, 2023 20:51
@SimplyDanny
Copy link
Collaborator

An observation for this rule in general: The exception for Bool seems to be quite arbitrary. What about var j: Int = 7 or var d: Double = 1.3 or let s: String = "my string"?

I wonder if we should rather extend the rule for these cases and rename the new option ignore_booleans to ignore_literals.

@revolter: You added the exception for Bool back then. Anything that speaks against my suggestions?

@garricn garricn force-pushed the add-redundant-type-annotation-configuration branch 3 times, most recently from e16a7f6 to 1302af9 Compare February 21, 2023 19:40
@garricn
Copy link
Contributor Author

garricn commented Feb 21, 2023

An observation for this rule in general: The exception for Bool seems to be quite arbitrary. What about var j: Int = 7 or var d: Double = 1.3 or let s: String = "my string"?

I wonder if we should rather extend the rule for these cases and rename the new option ignore_booleans to ignore_literals.

@revolter: You added the exception for Bool back then. Anything that speaks against my suggestions?

Hi @SimplyDanny, thank you for your observation. The examples you gave are not currently triggering examples and booleans are the only literals that currently violate this rule. It makes sense that numeric and string literals are not violations since you may need to be explicit that the type in let foo = 0 is actually an Int, Double, or Float. Or, in let foo = "someString", you may need to be explicit that foo is a String or StaticString. This is why we made the determination to implement this as ignore_booleans instead of something like ignore_literals.

@SimplyDanny
Copy link
Collaborator

Well, without the explizit types, the variables j, d and s would have the same type as specified. They are the defaults.

The current implementation checks exactly for the combinations Bool = true and Bool = false. The same could be done for Int = <any integer>, Double = <any float>, ...

Moreover, a variable being assigned a Boolean literal is not necessarily a Bool. That also works for types conforming to ExpressibleByBooleanLiteral.

The exception for Bool is still not clear to me yet.

@garricn garricn force-pushed the add-redundant-type-annotation-configuration branch from 1302af9 to 5c2907c Compare February 28, 2023 00:51
@garricn
Copy link
Contributor Author

garricn commented Feb 28, 2023

Well, without the explizit types, the variables j, d and s would have the same type as specified. They are the defaults.

The current implementation checks exactly for the combinations Bool = true and Bool = false. The same could be done for Int = <any integer>, Double = <any float>, ...

Moreover, a variable being assigned a Boolean literal is not necessarily a Bool. That also works for types conforming to ExpressibleByBooleanLiteral.

The exception for Bool is still not clear to me yet.

Thank you for your reply @SimplyDanny. The original intent for the special handling of Bool is not discernible from the PR or the issue.

My guess is that we would not want any of the following to be violations because, in certain cases, we might need to be explicit about the type:

let someInt: Int = 0
let someDouble: Double = 0
let someFloat: Float = 0
let someString: String = "foo"
let someStaticString: StaticString =  "bar"
let someCustomBool: CustomBool = false

However, in the case of Bool, we do not need to be explicit when defining one because Bool is the only conforming type to ExpressibleByBooleanLiteral in the Swift Standard Library.

https://developer.apple.com/documentation/swift/expressiblebystringliteral#conforming-types
https://developer.apple.com/documentation/swift/expressiblebyintegerliteral#conforming-types
https://developer.apple.com/documentation/swift/expressiblebyfloatliteral#conforming-types

Granted, you can create your own type that is ExpressibleByBooleanLiteral (like CustomBool above), but in that case you would want to be explicit about the type and you would not want the rule to trigger a violation.

Although I think your point is a valuable one, I believe it is outside the scope of this PR and so I'd like to suggest the following way forward:

  1. Move ahead with this PR as is
  2. Separately from this PR, other PRs in the future could consider removing custom handling of booleans or alternatively adding custom handling for all literal types

@SimplyDanny
Copy link
Collaborator

Although I think your point is a valuable one, I believe it is outside the scope of this PR and so I'd like to suggest the following way forward:

  1. Move ahead with this PR as is
  2. Separately from this PR, other PRs in the future could consider removing custom handling of booleans or alternatively adding custom handling for all literal types

That might be an acceptable way to go. However, I still take exception to the option's name ignore_booleans which is obviously very specific for Booleans. Changing an options name later on might cause trouble for users, unfortunately. That's why I'm still opposed to just adding it immediately.

@garricn garricn force-pushed the add-redundant-type-annotation-configuration branch from 5c2907c to 9e25db1 Compare March 16, 2023 00:17
@garricn garricn force-pushed the add-redundant-type-annotation-configuration branch from 9e25db1 to 99ddb9f Compare December 14, 2023 00:44
@tinder-cfuller
Copy link
Contributor

Reading through the comments, it really feels like the decision to have let someBool: Bool = true violate a rule named RedundantTypeAnnotation was possibly not the best decision in the first place, and is likely the cause for some confusion I am seeing in the comments.

I would like to reiterate that var j: Int = 7, var d: Double = 1.3 and let s: String = "my string" do NOT violate RedundantTypeAnnotation. For some reason only the boolean check was added to RedundantTypeAnnotation (and hence why this PR is proposing only adding the exception for booleans – there would be no reason for the option to be ignore_literals since the other literals are not violations).

I would like to kindly suggest an alternative way forward:

  • Revise this pull request to instead completely remove the boolean check from RedundantTypeAnnotation.
  • Submit another pull request to add a new opt-in rule to treat boolean literals with explicit type annotations as violations named BooleanLiteralTypeAnnotation – or LiteralTypeAnnotation if it is preferred that all literals with explicit types are violations.

With this approach, there is no need for a configuration option at all.

@SimplyDanny Would this alternative approach be accepted? And do you prefer BooleanLiteralTypeAnnotation or LiteralTypeAnnotation for the new rule?

Thank you 🙏

@revolter
Copy link
Contributor

For clarity: I was the one that requested this (in #3423), but I didn't make any code change for it.


As far as the current situation goes, I would be fine with reverting that change completely.

Bool is the only conforming type to ExpressibleByBooleanLiteral in the Swift Standard Library

but this can change in the future, so I would say that considering

let test: Bool = true

to be redundant is a guess, while considering

let test: URL = URL()

to be redundant is a certainty.

@SimplyDanny
Copy link
Collaborator

I'd like to avoid exceptions for certain cases that actually should follow the same rules as others. Breaking changes are acceptable if they really fix an inconstancy or harmonize implementations.

The exception for booleans bugs me, with or without the ignore_booleans option.

Types can conform to any ExpressibleBy...Literal to make them be initializable with the corresponding literal. But all literals are as well associated with a default type. So if the rule talks about "redundant types" I'd consider explicit default types for literals redundant. Booleans follow the same logic; I don't see why there ought to be any special handling for them (as of now or with an option).

Since there might be people not agreeing on the statement that default types can be considered redundant, my favorite is still this ignore_literals or perhaps the better consider_default_literal_types_redundant to be more specific. With that set to true,

let k: Int = 0
let d: Double = 0.0
let s: String = ""
let b: Bool = false

would all trigger while

let k: Int8 = 0
let d: Double = 0
let s: Name = ""
let b: OnOff = true

would not.

@tinder-cfuller
Copy link
Contributor

@SimplyDanny Thank you for weighing in. Very much appreciated 👍

So, to confirm, you are suggesting that on this PR, the ignore_booleans option be renamed to consider_default_literal_types_redundant, defaulted to true, is that correct?

As far as treating Int, Double and String literals as redundant, are you suggesting that this capability is also added on this PR as well? Asking since those are not treated as redundant currently and we are seeking to have this PR merged in sooner than later, so would like to optimize the changes for your approval. Please confirm. Thank you!

@SimplyDanny
Copy link
Collaborator

So, to confirm, you are suggesting that on this PR, the ignore_booleans option be renamed to consider_default_literal_types_redundant, defaulted to true, is that correct?

Yes, that's what feels most reasonable to me. However, the default should be false so that for most types/literals this doesn't change the rule's behavior - only for Bool in that the rule with default settings wouldn't trigger on let b: Bool = true while it currently does. For people already having the rule active, no surprising behavioral changes would come with an update to a new SwiftLint version in that way.

Any noticeable flaw in my reasoning?

@tinder-cfuller
Copy link
Contributor

@SimplyDanny Sounds good 👍 … consider_default_literal_types_redundant will default to false. Thank you for confirming that.

And may treating Int, Double and String literals as redundant be added on a separate PR (potentially by someone else), to limit the scope of the change on this PR?

@SimplyDanny
Copy link
Collaborator

And may treating Int, Double and String literals as redundant be added on a separate PR (potentially by someone else), to limit the scope of the change on this PR?

Well, ideally we would have all types properly supported right from the new option's introduction on. 😉

@garricn garricn force-pushed the add-redundant-type-annotation-configuration branch from 99ddb9f to 5ae7962 Compare April 16, 2024 23:19
@garricn garricn changed the title Add RedundantTypeAnnotationConfiguration for ignore_booleans option Add consider_default_literal_types_redundant option to RedundantTypeAnnotationRule Apr 16, 2024
@garricn garricn changed the title Add consider_default_literal_types_redundant option to RedundantTypeAnnotationRule Add consider_default_literal_types_redundant option to RedundantTypeAnnotationRule Apr 16, 2024
@garricn garricn changed the title Add consider_default_literal_types_redundant option to RedundantTypeAnnotationRule Add consider_default_literal_types_redundant option to RedundantTypeAnnotationRule Apr 16, 2024
@garricn
Copy link
Contributor Author

garricn commented Apr 17, 2024

@SimplyDanny Thanks again for all the feedback. I investigated adding validations for Int, Double and String literals and determined that an overhaul of the rule, potentially adopting SwiftSyntax, would likely be required. Since that would significantly increase the scope and complexity of the PR, I propose that the PR is limited to adding the new config option only. I've updated to use the option renamed as you requested, and it's working really well! My hope is that you will consider merging this as is and allow the additional type support to be added later. I look forward to hearing back from you. Thank you 😄

@SimplyDanny
Copy link
Collaborator

@SimplyDanny Thanks again for all the feedback. I investigated adding validations for Int, Double and String literals and determined that an overhaul of the rule, potentially adopting SwiftSyntax, would likely be required. Since that would significantly increase the scope and complexity of the PR, I propose that the PR is limited to adding the new config option only. I've updated to use the option renamed as you requested, and it's working really well! My hope is that you will consider merging this as is and allow the additional type support to be added later. I look forward to hearing back from you. Thank you 😄

The rewrite with SwiftSyntax is now done with #5389 just being merged. I would still appreciate you implementing all cases to have this in a complete and reasonable shape. With the rewrite, this ought not to be that complex. Otherwise, we need to wait for me or another contributor to find the time to address this.

@garricn garricn force-pushed the add-redundant-type-annotation-configuration branch from de97b68 to a53efa1 Compare April 24, 2024 01:03
@tinder-cfuller
Copy link
Contributor

@SimplyDanny The rewrite of the rule with SwiftSyntax makes this much more straightforward! Very cool! 👍

@garricn Thank you for implementing this! ❤️

CHANGELOG.md Outdated Show resolved Hide resolved
@garricn garricn force-pushed the add-redundant-type-annotation-configuration branch from a53efa1 to 3b222cf Compare April 26, 2024 00:09
Copy link
Contributor

@tinder-cfuller tinder-cfuller left a comment

Choose a reason for hiding this comment

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

Thanks again Garric! Looking forward to using this new option! 👍

I added two small suggestions, but they are very minor, so only use if you see a benefit.

I do have one question though, which is whether we need to indicate somewhere that Bool literals will no longer be considered redundant by default. Since this is a change in behavior, does it need to be listed as a "breaking" change?

@SimplyDanny
Copy link
Collaborator

I do have one question though, which is whether we need to indicate somewhere that Bool literals will no longer be considered redundant by default. Since this is a change in behavior, does it need to be listed as a "breaking" change?

Yes, I'd like that.

@garricn garricn force-pushed the add-redundant-type-annotation-configuration branch from 19e20cd to c044d71 Compare May 1, 2024 18:43
Copy link
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

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

I like how that turned out. The new option makes a lot of sense to me and resolves an aged inconsistency.

@SimplyDanny SimplyDanny merged commit 16c0213 into realm:main May 1, 2024
12 checks passed
@tinder-cfuller
Copy link
Contributor

@SimplyDanny Thanks for all your guidance and attention on this! Very much appreciated ⭐

@garricn Great work! Thank you again for making this improvement.

@SimplyDanny
Copy link
Collaborator

SimplyDanny commented May 1, 2024

Just to let you guys know: I made a few cleanups to reduce some duplications in #5554. Didn't want to prolong the review here while being pedantic. 😅

I also enabled the option directly in SwiftLint itself (#5555).

@tinder-cfuller
Copy link
Contributor

@SimplyDanny That's great! 👏

@garricn garricn deleted the add-redundant-type-annotation-configuration branch May 15, 2024 23:36
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