SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Add new `private_swiftui_state_property` rule

Open mt00chikin opened this issue 2 years ago β€’ 1 comments

This creates a new opt-in rule that requires that SwiftUI state properties be declared as private. This is inspired by Apple's documentation for State:

To avoid this, always declare state as private, and place it in the highest view in the view hierarchy that needs access to the value

This only covers @State and not other SwiftUI property wrappers like @StateObject or @EnvironmentObject.

This MR attempts to address requests from issue: https://github.com/realm/SwiftLint/issues/3173

mt00chikin avatar Feb 16 '23 16:02 mt00chikin

168 Warnings
:warning: This PR introduced a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/PlaylistMenuButton.swift:86:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/BuySendSwap/SwapCryptoView.swift:170:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift:100:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift:102:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift:104:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift:106:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift:109:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift:111:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/FiltersDisplaySettingsView.swift:98:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/Market/MarketView.swift:21:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/NetworkFilterView.swift:20:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/Portfolio/EditUserAssetsView.swift:18:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Brave: /Sources/BraveWallet/Crypto/Search/SendTokenSearchView.swift:15:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/AppTPActivityView.swift:33:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/AppTPManageTrackerCell.swift:25:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/AppTPManageTrackersView.swift:29:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/AppTPManageTrackersView.swift:30:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/AppTPTrackerDetailView.swift:29:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/AppTPTrackerDetailView.swift:30:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/AutofillLoginPromptView.swift:25:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/CustomDaxDialog.swift:27:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/DownloadsList.swift:26:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/HomeMessageView.swift:46:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/OmniBarNotification.swift:26:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/OmniBarNotification.swift:28:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/OmniBarNotification.swift:29:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/OmniBarNotification.swift:31:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/OnboardingContainerView.swift:32:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/PasswordGenerationPromptView.swift:25:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /DuckDuckGo/SaveLoginView.swift:33:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /LocalPackages/SyncUI/Sources/SyncUI/Views/DeviceConnectedView.swift:31:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /LocalPackages/SyncUI/Sources/SyncUI/Views/Internal/ConnectModeView.swift:27:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /LocalPackages/SyncUI/Sources/SyncUI/Views/Internal/PasteCodeView.swift:30:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /LocalPackages/SyncUI/Sources/SyncUI/Views/Internal/UnderflowContainer.swift:35:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /LocalPackages/SyncUI/Sources/SyncUI/Views/Internal/UnderflowContainer.swift:36:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /LocalPackages/SyncUI/Sources/SyncUI/Views/Internal/UnderflowContainer.swift:41:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /LocalPackages/SyncUI/Sources/SyncUI/Views/Internal/UnderflowContainer.swift:46:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /LocalPackages/SyncUI/Sources/SyncUI/Views/ScanOrPasteCodeView.swift:31:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /LocalPackages/SyncUI/Sources/SyncUI/Views/SyncSettingsView.swift:65:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in DuckDuckGo: /LocalPackages/SyncUI/Sources/SyncUI/Views/TurnOnSyncView.swift:31:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardInputView.swift:18:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardInputView.swift:19:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardInputView.swift:20:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardInputView.swift:21:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardInputView.swift:22:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardItemRow.swift:21:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardItemRow.swift:22:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardItemRow.swift:23:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardItemRow.swift:24:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardItemRow.swift:25:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardItemRow.swift:26:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardSectionHeader.swift:13:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardSettingsEmptyView.swift:14:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardSettingsEmptyView.swift:15:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardSettingsEmptyView.swift:16:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/CreditCardSettingsView/CreditCardSettingsEmptyView.swift:17:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/CreditCardAutofillToggle.swift:32:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/CreditCardAutofillToggle.swift:33:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/CreditCardAutofillToggle.swift:34:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/CreditCardInputField.swift:29:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/CreditCardInputField.swift:30:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/CreditCardInputField.swift:41:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/CreditCardInputField.swift:42:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/CreditCardInputField.swift:43:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/CreditCardInputField.swift:44:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/RemoveCardButton.swift:26:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/RemoveCardButton.swift:27:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/RemoveCardButton.swift:28:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Firefox: /Client/Frontend/Autofill/CreditCard/ViewComponents/ToastView.swift:12:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in Kickstarter: /Kickstarter-iOS/SharedViews/LoadingBarButtonItem.swift:8:10: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in NetNewsWire: /iOS/Account/FeedbinAddAccountView.swift:20:9: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in NetNewsWire: /iOS/Account/NewsBlurAddAccountView.swift:18:9: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in NetNewsWire: /iOS/Account/ReaderAPIAddAccountView.swift:21:9: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /Pocket Casts Watch App Extension/PodcastsListView.swift:28:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /Pocket Casts Watch App Extension/PodcastsListView.swift:45:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/App Icon/AppIconWidget.swift:20:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Common/ArtworkViews.swift:33:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Common/ArtworkViews.swift:4:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Now Playing/NowPlayingEntryView.swift:5:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Now Playing/NowPlayingLockScreenWidget.swift:20:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Up Next/EpisodeView.swift:5:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Up Next/EpisodeView.swift:6:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Up Next/UpNextLargeWidgetView.swift:5:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Up Next/UpNextLargeWidgetView.swift:6:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Up Next/UpNextLargeWidgetView.swift:7:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Up Next/UpNextLockScreenWidget.swift:21:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Up Next/UpNextMediumWidgetView.swift:5:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Up Next/UpNextMediumWidgetView.swift:6:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Up Next/UpNextMediumWidgetView.swift:7:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /WidgetExtension/Up Next/UpNextWidgetEntryView.swift:5:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/AboutView.swift:163:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/AboutView.swift:164:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/AboutView.swift:165:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/AboutView.swift:166:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/ChoosePodcastFolderView.swift:85:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/ColorPreviewFolderView.swift:82:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/ColorSelectCircle.swift:6:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/EditFolderView.swift:9:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/End of Year/Views/CircularProgressView.swift:49:16: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/End of Year/Views/CircularProgressView.swift:50:16: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/NameFolderView.swift:13:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/New Search/Views/Results/SearchResultsView.swift:11:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/New Search/Views/Results/SearchResultsView.swift:13:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/New Search/Views/Results/SearchResultsView.swift:14:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Import/ImportDetailsView.swift:13:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Import/ImportDetailsView.swift:14:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Import/ImportDetailsView.swift:15:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Import/ImportDetailsView.swift:16:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Login/LoginLandingView.swift:290:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Login/LoginLandingView.swift:58:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Login/LoginLandingView.swift:61:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Plus/PlusLandingView.swift:6:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Plus/PlusPurchaseModal.swift:144:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Plus/PlusPurchaseModal.swift:8:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Plus/PlusPurchaseModal.swift:9:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Plus/UpgradeLandingView.swift:192:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/Onboarding/Plus/UpgradeLandingView.swift:344:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/PodcastPickerRow.swift:10:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/PodcastPickerView.swift:83:12: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/SwiftUI/ActionBarOverlayView.swift:151:16: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/SwiftUI/ActionBarOverlayView.swift:152:16: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/SwiftUI/HighlightedText.swift:202:16: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/SwiftUI/HorizontalCarousel.swift:303:16: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/SwiftUI/HorizontalCarousel.swift:304:16: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/SwiftUI/HorizontalCarousel.swift:305:16: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: This PR introduced a violation in PocketCasts: /podcasts/SwiftUI/HorizontalCarousel.swift:306:16: warning: Private SwiftUI @State Properties Violation: SwiftUI state properties should be private (private_swiftui_state)
:warning: Danger found 168 violations with this PR. Due to GitHub's max issue comment size, the number shown has been truncated to 126.
17 Messages
:book: Linting Aerial with this PR took 1.16s vs 1.15s on main (0% slower)
:book: Linting Alamofire with this PR took 1.48s vs 1.49s on main (0% faster)
:book: Linting Brave with this PR took 8.5s vs 8.5s on main (0% slower)
:book: Linting DuckDuckGo with this PR took 4.11s vs 4.1s on main (0% slower)
:book: Linting Firefox with this PR took 9.96s vs 9.91s on main (0% slower)
:book: Linting Kickstarter with this PR took 10.83s vs 10.84s on main (0% faster)
:book: Linting Moya with this PR took 0.61s vs 0.62s on main (1% faster)
:book: Linting NetNewsWire with this PR took 3.29s vs 3.26s on main (0% slower)
:book: Linting Nimble with this PR took 0.79s vs 0.79s on main (0% slower)
:book: Linting PocketCasts with this PR took 8.44s vs 8.42s on main (0% slower)
:book: Linting Quick with this PR took 0.4s vs 0.39s on main (2% slower)
:book: Linting Realm with this PR took 13.72s vs 13.8s on main (0% faster)
:book: Linting Sourcery with this PR took 2.42s vs 2.4s on main (0% slower)
:book: Linting Swift with this PR took 5.49s vs 5.45s on main (0% slower)
:book: Linting VLC with this PR took 1.45s vs 1.47s on main (1% faster)
:book: Linting Wire with this PR took 8.95s vs 8.96s on main (0% faster)
:book: Linting WordPress with this PR took 12.98s vs 12.93s on main (0% slower)

Generated by :no_entry_sign: Danger

SwiftLintBot avatar Feb 16 '23 16:02 SwiftLintBot

I updated the branch based on your feedback and suggestions, they all looked good to me. As far as making this correctable, that seems like a good addition to this rule. I'll have to dig into the Rewriter code a bit to figure out how it's implemented, but I'd be happy to try and get that working as well.

mt00chikin avatar Feb 20 '23 02:02 mt00chikin

Right now this rule only requires that SwiftUI @State properties be private since this is explicitly recommended in Apple's documentation, but I could potentially see an argument for adding @StateObject as well. I didn't want the scope of the rule to be too broad, so I left that one (along with @EnvironmentObject and @ObservedObject) out of this initial pass.

mt00chikin avatar Feb 20 '23 15:02 mt00chikin

@SimplyDanny With the advent of Swift macros and thus @StateObject being phased out, I believe this is a good-enough starting point, no more attributed needed πŸ‘

DivineDominion avatar Jul 14 '23 08:07 DivineDominion

@SimplyDanny With the advent of Swift macros and thus @StateObject being phased out, I believe this is a good-enough starting point, no more attributed needed πŸ‘

Convinced. Are you willing to rebase the PR and resolve all conflicts, @mt00chikin?

SimplyDanny avatar Jul 14 '23 18:07 SimplyDanny

@SimplyDanny absolutely, I'll try to get that addressed soon and get updates pushed up.

mt00chikin avatar Jul 17 '23 13:07 mt00chikin

No worries, @SimplyDanny! I appreciate the feedback. Let me know if there's anything else in my latest commit that might have been overlooked.

mt00chikin avatar Jul 24 '23 23:07 mt00chikin

There are actually two more things that I've just thought of ...

When a declaration is nested inside another declaration implementing View like

struct ContentView: View {
    struct OtherStruct {
        @State var isPlaying: Bool = false   // rule doesn't trigger
    }
}

the rule doesn't trigger in the nested type. That's fine. However, if it's the other way around as in

struct OtherStruct {
    struct ContentView: View {
        @State var isPlaying: Bool = false    // rule doesn't trigger
    }
}

it also doesn't trigger and that'd be incorrect. It should trigger. We'd have to keep track of the scope we are currently in instead of skipping the type's body completely.

Other than that, Apple's documentation you referred to states

Create a state value in an App, Scene, or View by applying the @State attribute to a property declaration and providing an initial value.

which means the rule should not only check for conformance to View but to App and Scene as well.

SimplyDanny avatar Jul 26 '23 19:07 SimplyDanny

Let's see if the following example works:

struct MyStruct {
    struct ContentView: View {
        @State ↓var isPlaying: Bool = false
    }
    @State var isPlaying: Bool = false
}

SimplyDanny avatar Jul 28 '23 07:07 SimplyDanny

It doesn't. That's what I get for trying to do this late at night... Is there a way to determine when a Visitor has exited a node? I don't see anything in the protocol that looks like it would tell me that. I'm guessing I'll have to use the parent to determine the current context when visiting a node? I might have to put this on hold for a bit, work has been busy lately and I'll be on vacation next week. I'll see if I can't get something actually working today, but it'll probably be the week after next before I can get this wrapped up.

mt00chikin avatar Jul 28 '23 14:07 mt00chikin

Ok, I fundamentally misinterpreted visitPost(_:) before today. Needed to read the docs more thoroughly, that was my mistake. I believe I have your latest test case working correctly now, but I'm going to do some additional testing and try to clean the code up a bit where possible.

mt00chikin avatar Jul 28 '23 16:07 mt00chikin

This is going to be merged soon. Thank you for your patience!

SimplyDanny avatar Jul 28 '23 19:07 SimplyDanny

Thank you! I appreciate the thorough and patient review feedback. I definitely learned a lot about SwiftSyntax from this experience.

mt00chikin avatar Jul 28 '23 20:07 mt00chikin

Has this rule been released? I'm trying to use it but I'm getting 'warning: 'private_swiftui_state' is not a valid rule identifier' and the response from 'swiftlint rules' doesn't contain it. Im on version '0.52.4'

calebwilson706 avatar Aug 22 '23 14:08 calebwilson706

Has this rule been released? I'm trying to use it but I'm getting 'warning: 'private_swiftui_state' is not a valid rule identifier' and the response from 'swiftlint rules' doesn't contain it. Im on version '0.52.4'

No, it's not yet been released.

SimplyDanny avatar Aug 22 '23 14:08 SimplyDanny

I personally think the same rule should apply to @StateObject.

ObjectiveCesar avatar Aug 25 '23 10:08 ObjectiveCesar

You and Apple both :) https://developer.apple.com/documentation/swiftui/stateobject#

Just want to say that this is not a matter of preference whether a @StateObject should be changed from "outside" its owning view. One can try, but it's a source of problems.

DivineDominion avatar Aug 25 '23 19:08 DivineDominion

I personally think the same rule should apply to @StateObject.

This is easy to achieve. Anyone willing to open a PR? 😊

SimplyDanny avatar Aug 26 '23 08:08 SimplyDanny

If no one has already started on that work, I can probably find some time to add it this week or next! I actually had considered adding this from the outset, but it just got lost along the way. I'd be happy to add it, I think that it's a good addition to the rule

mt00chikin avatar Aug 29 '23 19:08 mt00chikin

If no one has already started on that work, I can probably find some time to add it this week or next! I actually had considered adding this from the outset, but it just got lost along the way. I'd be happy to add it, I think that it's a good addition to the rule

Thank you for making the effort. I certainly appreciate it.

ObjectiveCesar avatar Aug 29 '23 20:08 ObjectiveCesar

FYI, I've opened https://github.com/realm/SwiftLint/pull/5200 to address this feedback and apply the rule to StateObject as well. Feel free to comment on that MR with any additional concerns or requests

mt00chikin avatar Sep 01 '23 14:09 mt00chikin