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

Ignore no_magic_numbers violations if they are in an extension of a test class (only works in the same file) #5146

Conversation

mildm8nnered
Copy link
Collaborator

@mildm8nnered mildm8nnered commented Jul 30, 2023

Ignores violations if they are present in an extension, if that extension extends a child of the specified testParentClasses, as long as the class declaration is in the same source file.

Partially resolves #5137

This was harder that I thought, and also more useful than expected, given the number of violations this (apparently correctly) fixes in the OSS tests.

We now keep track of class declarations, and whether they inherit from testParentClasses or not.

When we see a violation in an extension, unless we already know that it extends a test class, we add it to the violations.

If later in the file, we see the class declaration, and it extends one of the testParentClasses, we remove the violations from the list.

This should work no matter where in the file the class declaration occurs.

@SwiftLintBot
Copy link

SwiftLintBot commented Jul 30, 2023

1 Warning
⚠️ This PR may need tests.
80 Messages
📖 Linting Aerial with this PR took 1.1s vs 1.12s on main (1% faster)
📖 Linting Alamofire with this PR took 1.43s vs 1.44s on main (0% faster)
📖 Linting Brave with this PR took 8.09s vs 8.15s on main (0% faster)
📖 Linting DuckDuckGo with this PR took 3.99s vs 4.02s on main (0% faster)
📖 Linting Firefox with this PR took 9.57s vs 9.64s on main (0% faster)
📖 Linting Kickstarter with this PR took 10.33s vs 10.39s on main (0% faster)
📖 Linting Moya with this PR took 0.59s vs 0.61s on main (3% faster)
📖 Linting NetNewsWire with this PR took 3.12s vs 3.14s on main (0% faster)
📖 Linting Nimble with this PR took 0.76s vs 0.76s on main (0% slower)
📖 Linting PocketCasts with this PR took 8.07s vs 8.13s on main (0% faster)
📖 Linting Quick with this PR took 0.39s vs 0.38s on main (2% slower)
📖 Linting Realm with this PR took 11.16s vs 11.23s on main (0% faster)
📖 Linting Sourcery with this PR took 2.33s vs 2.39s on main (2% faster)
📖 Linting Swift with this PR took 5.19s vs 5.21s on main (0% faster)
📖 Linting VLC with this PR took 1.4s vs 1.41s on main (0% faster)
📖 Linting Wire with this PR took 8.59s vs 8.61s on main (0% faster)
📖 Linting WordPress with this PR took 12.21s vs 12.27s on main (0% faster)
📖 This PR fixed a violation in Firefox: /BrowserKit/Tests/SiteImageViewTests/ImageProcessing/LetterImageGeneratorTests.swift:83:50: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /BrowserKit/Tests/SiteImageViewTests/ImageProcessing/LetterImageGeneratorTests.swift:84:54: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /BrowserKit/Tests/SiteImageViewTests/ImageProcessing/LetterImageGeneratorTests.swift:85:52: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /BrowserKit/Tests/SiteImageViewTests/ImageProcessing/LetterImageGeneratorTests.swift:86:54: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Frontend/Home/Pocket/PocketSponsoredStoriesProviderTests.swift:164:46: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Frontend/Home/Pocket/PocketSponsoredStoriesProviderTests.swift:164:68: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Frontend/Home/TopSites/ContileProviderTests.swift:230:46: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Frontend/Home/TopSites/ContileProviderTests.swift:230:68: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Helpers/RatingPromptManagerTests.swift:238:38: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Helpers/RecentItemsHelperTests.swift:188:35: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/RemoteTabsPanelTests.swift:132:38: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/TabDisplayManagerTests.swift:502:38: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/TabManagement/Legacy/LegacyTabManagerTests.swift:694:38: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/TabManagement/Legacy/LegacyTabManagerTests.swift:713:44: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/TabManagement/Legacy/LegacyTabManagerTests.swift:716:37: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/TabManagement/Legacy/LegacyTabManagerTests.swift:717:37: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/TabManagement/Legacy/LegacyTabManagerTests.swift:734:44: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/TabManagement/Legacy/LegacyTabManagerTests.swift:737:37: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/TabManagement/Legacy/LegacyTabManagerTests.swift:738:37: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/TabManagement/Legacy/TabManagerNavDelegateTests.swift:181:47: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/TabManagement/Legacy/TabManagerNavDelegateTests.swift:181:60: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Utils/GeneralizedImageFetcherTests.swift:118:46: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Utils/GeneralizedImageFetcherTests.swift:118:68: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Utils/HistoryDeletionUtilityTests.swift:325:38: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Utils/HistoryDeletionUtilityTests.swift:342:38: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Utils/HistoryDeletionUtilityTests.swift:397:68: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Utils/HistoryDeletionUtilityTests.swift:445:68: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/ClientTests/Utils/HistoryDeletionUtilityTests.swift:499:115: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/AsyncReducerTests.swift:110:47: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/AsyncReducerTests.swift:114:40: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/AsyncReducerTests.swift:114:43: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/AsyncReducerTests.swift:114:46: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/AsyncReducerTests.swift:114:49: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/AsyncReducerTests.swift:122:47: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/AsyncReducerTests.swift:126:40: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/AsyncReducerTests.swift:128:15: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/AsyncReducerTests.swift:129:41: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/AsyncReducerTests.swift:129:44: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/AsyncReducerTests.swift:129:47: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:105:106: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:110:57: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:113:106: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:133:64: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:141:55: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:142:55: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:78:82: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:79:46: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:80:45: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:84:95: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:85:45: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:89:90: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:90:45: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:94:90: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Firefox: /Tests/SharedTests/FeatureSwitchTests.swift:97:26: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /Screenshot Automation Watch/Watch_GenerateScreenshots.swift:80:77: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /Screenshot Automation Watch/Watch_GenerateScreenshots.swift:83:81: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /Screenshot Automation/GenerateScreenshots.swift:100:72: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /Screenshot Automation/GenerateScreenshots.swift:55:65: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /Screenshot Automation/GenerateScreenshots.swift:59:62: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in PocketCasts: /Screenshot Automation/GenerateScreenshots.swift:95:53: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in WordPress: /WordPress/WordPressTest/DataMigratorTests.swift:346:77: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in WordPress: /WordPress/WordPressTest/PromptRemindersSchedulerTests.swift:395:83: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in WordPress: /WordPress/WordPressTest/PromptRemindersSchedulerTests.swift:406:23: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants (no_magic_numbers)

Generated by 🚫 Danger

@mildm8nnered mildm8nnered force-pushed the mildm8nnered-ignore-magic-numbers-in-extensions-of-test-cases branch from d423c44 to fd94ec1 Compare July 30, 2023 15:51
@mildm8nnered mildm8nnered changed the title Ignore no magic numbers violations if they are in an extension of a test class (only works in the same file) Ignore no_magic_numbers violations if they are in an extension of a test class (only works in the same file) Jul 31, 2023
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.

Looks good. I like how you achieve to traverse the AST only once!

Yet, like so often, I have some remarks ...

@mildm8nnered mildm8nnered force-pushed the mildm8nnered-ignore-magic-numbers-in-extensions-of-test-cases branch from 1fffbb4 to 77006c2 Compare August 2, 2023 20:51
@mildm8nnered
Copy link
Collaborator Author

Looks good. I like how you achieve to traverse the AST only once!

Yet, like so often, I have some remarks ...

My heart always sinks a little at first, but the code ends up so much better for your feedback :-)

I wish I got code reviews like that in my day job.

@SimplyDanny
Copy link
Collaborator

Looks good. I like how you achieve to traverse the AST only once!
Yet, like so often, I have some remarks ...

My heart always sinks a little at first, but the code ends up so much better for your feedback :-)

I wish I got code reviews like that in my day job.

Haha ... thank you for the kind feedback! I appreciate your continuous and well thought out contributions.

@mildm8nnered mildm8nnered force-pushed the mildm8nnered-ignore-magic-numbers-in-extensions-of-test-cases branch from f836039 to 7d21b47 Compare August 3, 2023 21:19
@SimplyDanny SimplyDanny merged commit e9c2285 into realm:main Aug 5, 2023
5 checks passed
@mildm8nnered mildm8nnered deleted the mildm8nnered-ignore-magic-numbers-in-extensions-of-test-cases branch August 30, 2023 18:04
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.

extension of test class should NOT trigger no_magic_numbers rule
3 participants