Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

no_magic_numbers rule now ignores violations in Preview macros #5778

Conversation

mildm8nnered
Copy link
Collaborator

@mildm8nnered mildm8nnered commented Aug 31, 2024

Addresses #5775

violations of no_magic_numbers in SwiftUI's Preview macros (or any macro named Preview) will be ignored.

@SwiftLintBot
Copy link

SwiftLintBot commented Aug 31, 2024

67 Messages
📖 Linting Aerial with this PR took 0.16s vs 0.17s on main (5% faster)
📖 Linting Alamofire with this PR took 0.16s vs 0.17s on main (5% faster)
📖 Linting Brave with this PR took 0.76s vs 0.75s on main (1% slower)
📖 Linting DuckDuckGo with this PR took 0.52s vs 0.53s on main (1% faster)
📖 Linting Firefox with this PR took 1.45s vs 1.46s on main (0% faster)
📖 Linting Kickstarter with this PR took 0.86s vs 0.85s on main (1% slower)
📖 Linting Moya with this PR took 0.11s vs 0.11s on main (0% slower)
📖 Linting NetNewsWire with this PR took 0.32s vs 0.32s on main (0% slower)
📖 Linting Nimble with this PR took 0.13s vs 0.13s on main (0% slower)
📖 Linting PocketCasts with this PR took 0.88s vs 0.88s on main (0% slower)
📖 Linting Quick with this PR took 0.11s vs 0.11s on main (0% slower)
📖 Linting Realm with this PR took 0.45s vs 0.46s on main (2% faster)
📖 Linting Sourcery with this PR took 0.29s vs 0.29s on main (0% slower)
📖 Linting Swift with this PR took 0.51s vs 0.5s on main (2% slower)
📖 Linting VLC with this PR took 0.21s vs 0.21s on main (0% slower)
📖 Linting Wire with this PR took 1.89s vs 1.86s on main (1% slower)
📖 Linting WordPress with this PR took 1.28s vs 1.27s on main (0% slower)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/PageSecurityView.swift:100:19: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /Sources/Brave/Frontend/Browser/Toolbars/PageSecurityView.swift:99:45: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in DuckDuckGo: /DuckDuckGo/FavoriteIconView.swift:62:21: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in DuckDuckGo: /DuckDuckGo/FavoriteItemView.swift:74:121: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in DuckDuckGo: /DuckDuckGo/FavoriteItemView.swift:75:192: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in DuckDuckGo: /DuckDuckGo/NewTabPageIntroMessageView.swift:72:46: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in DuckDuckGo: /DuckDuckGo/SettingsCell.swift:391:33: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in DuckDuckGo: /DuckDuckGo/ShortcutAccessoryView.swift:82:65: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in DuckDuckGo: /DuckDuckGo/ShortcutAccessoryView.swift:83:70: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in DuckDuckGo: /DuckDuckGo/ShortcutItemView.swift:118:57: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in DuckDuckGo: /DuckDuckGo/ShortcutItemView.swift:128:39: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in DuckDuckGo: /DuckDuckGo/ShortcutItemView.swift:130:39: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in DuckDuckGo: /DuckDuckGo/ShortcutItemView.swift:134:18: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in DuckDuckGo: /DuckDuckGo/Subscription/Views/SubscriptionSettingsHeaderView.swift:78:21: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Kickstarter-iOS/Features/PaginationExample/PaginationExampleView.swift:76:8: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Kickstarter-iOS/Features/PaginationExample/PaginationExampleView.swift:77:8: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOAddressSummary.swift:31:19: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOAddressSummary.swift:40:51: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOAddressSummary.swift:44:12: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOAlertFlag.swift:65:40: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOProjectCard.swift:146:23: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOProjectCreator.swift:57:19: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOProjectCreator.swift:62:12: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOProjectDetails.swift:75:51: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOProjectDetails.swift:83:51: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOProjectDetails.swift:87:12: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Kickstarter: /Library/PagedContainer/PagedTabBar.swift:111:59: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /Pocket Casts Watch App/MenuRow.swift:60:57: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Categories/CategoriesSelectorView.swift:186:27: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Categories/CategoriesSelectorView.swift:198:27: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Onboarding/Plus/UpgradeExperiment/Features/PlusPaywallFeatureCard.swift:118:23: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Onboarding/Plus/UpgradeExperiment/Features/PlusPaywallFeatureCard.swift:118:36: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Onboarding/Plus/UpgradeExperiment/Reviews/PlusPaywallReviewCard.swift:50:49: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Onboarding/Plus/UpgradeExperiment/Reviews/PlusPaywallReviewCard.swift:67:31: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Onboarding/Plus/UpgradeExperiment/Reviews/PlusPaywallReviewsPlusFeatures.swift:78:14: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Referrals/ReferralCardAnimatedGradientView.swift:110:40: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Referrals/ReferralCardAnimatedGradientView.swift:117:23: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Referrals/ReferralCardAnimatedGradientView.swift:118:23: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Referrals/ReferralCardAnimatedGradientView.swift:118:36: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Referrals/ReferralCardView.swift:45:43: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Referrals/ReferralCardView.swift:46:23: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /podcasts/Referrals/ReferralCardView.swift:46:36: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in WordPress: /WordPress/Classes/ApplicationToken/ApplicationTokenListView.swift:138:173: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in WordPress: /WordPress/Classes/ViewRelated/Post/Prepublishing/PublishButton.swift:127:21: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in WordPress: /WordPress/Classes/ViewRelated/Post/Prepublishing/PublishButton.swift:130:145: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in WordPress: /WordPress/Classes/ViewRelated/Voice/AudioRecorderVisualizerView.swift:70:30: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in WordPress: /WordPress/Classes/ViewRelated/Voice/AudioRecorderVisualizerView.swift:70:35: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in WordPress: /WordPress/Classes/ViewRelated/Voice/AudioRecorderVisualizerView.swift:70:39: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in WordPress: /WordPress/Classes/ViewRelated/Voice/AudioRecorderVisualizerView.swift:70:43: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in WordPress: /WordPress/Classes/ViewRelated/Voice/AudioRecorderVisualizerView.swift:70:47: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)

Generated by 🚫 Danger

@mildm8nnered mildm8nnered marked this pull request as ready for review August 31, 2024 16:59
@SimplyDanny
Copy link
Collaborator

I wonder if we should only ignore the #Preview macro specifically or come up with a more general "ignore these structures" setting which would allow to list names of structs, classes, macros, ...

@mildm8nnered mildm8nnered changed the title Adds a macros_to_ignore configuration setting Adds a macros_to_ignore configuration setting for the no_magic_numbers rule Sep 4, 2024
@mildm8nnered
Copy link
Collaborator Author

I wonder if we should only ignore the #Preview macro specifically or come up with a more general "ignore these structures" setting which would allow to list names of structs, classes, macros, ...

So right now, we'd ignore nothing at all by default, although Preview is a good candidate for a default setting.

It would be pretty easy to say if you're a child of any struct/class/macro named XXXX then ignore, but I think macros is an obvious use case, because you will probably have many #Preview's.

For a class or struct, there's only going to be one for any given name - I think it feels a bit cleaner for people to just

// swiftlint:disable no_magic_numbers at the top of that file (assuming that they configure blanket_disable_command to ignore no_magic_numbers, or suppress it locally).

@SimplyDanny
Copy link
Collaborator

I wonder if we should only ignore the #Preview macro specifically or come up with a more general "ignore these structures" setting which would allow to list names of structs, classes, macros, ...

So right now, we'd ignore nothing at all by default, although Preview is a good candidate for a default setting.

I tend to like a default "#Preview macros are ignored" more. Right now, I can't see other use cases for the new option. So we could just ignore the macro content without any option.

@SimplyDanny SimplyDanny added this to the 0.57.0 milestone Sep 7, 2024
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-disable-no-magic-numbers-in-preview-code branch from 5d4c598 to 8c7a03e Compare September 8, 2024 11:08
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-disable-no-magic-numbers-in-preview-code branch from 8c7a03e to 1d5d952 Compare September 8, 2024 11:35
@SimplyDanny
Copy link
Collaborator

I wonder if we should only ignore the #Preview macro specifically or come up with a more general "ignore these structures" setting which would allow to list names of structs, classes, macros, ...

So right now, we'd ignore nothing at all by default, although Preview is a good candidate for a default setting.

I tend to like a default "#Preview macros are ignored" more. Right now, I can't see other use cases for the new option. So we could just ignore the macro content without any option.

The question here is more whether we need an option at all. The rule could just ignore #Preview built-in. Anything that'd contradict that?

@mildm8nnered
Copy link
Collaborator Author

I wonder if we should only ignore the #Preview macro specifically or come up with a more general "ignore these structures" setting which would allow to list names of structs, classes, macros, ...

So right now, we'd ignore nothing at all by default, although Preview is a good candidate for a default setting.

I tend to like a default "#Preview macros are ignored" more. Right now, I can't see other use cases for the new option. So we could just ignore the macro content without any option.

The question here is more whether we need an option at all. The rule could just ignore #Preview built-in. Anything that'd contradict that?

Not that I know of, but I don't really use macros much myself in my day job. I'll ditch the configuration - we can always add in back in if another use case turns up.

@mildm8nnered mildm8nnered changed the title Adds a macros_to_ignore configuration setting for the no_magic_numbers rule no_magic_numbers rule now ignores violations in Preview macros Sep 8, 2024
@mildm8nnered mildm8nnered merged commit 8baec9e into realm:main Sep 8, 2024
13 checks passed
@mildm8nnered mildm8nnered deleted the mildm8nnered-disable-no-magic-numbers-in-preview-code branch September 8, 2024 13:23
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants