Recognise Color and NSColor in no_magic_numbers - #6870
Open
lechuckcaptain wants to merge 1 commit into
Open
Conversation
`no_magic_numbers` exempts the color-component arguments of a `UIColor` initializer, but the check hardcoded that one type name. SwiftUI's `Color` and AppKit's `NSColor` got no exemption at all, so their components were reported as magic numbers. Match all three type names, and accept module-qualified spellings such as `SwiftUI.Color`. Accept the `opacity` label alongside `alpha`, since SwiftUI spells it differently. Every literal is still judged by its own label, and the type name must match exactly: `DesignSystem.Color(red: 0.5, …)` and `UIColor(rgb: 0x33373A, …)` stay reported.
Generated by 🚫 Danger |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6869.
no_magic_numbersexempts the color components of aUIColorinitializer, but the check hardcoded that one type name, so SwiftUI'sColorand AppKit'sNSColorgot no exemption at all.SwiftUI.Color.opacitylabel alongsidealpha, since SwiftUI spells it differently.Every literal is still judged by its own label, and the type name must match exactly, so
DesignSystem.Color(red: 0.5, …)andUIColor(rgb: 0x33373A, …)stay reported. There are triggering examples pinning both.Two follow-ups, kept out of this PR to keep it small: the AppKit color-space labels such as
srgbRed, which is the second symptom in #6869, and components written as computations such as0x19 / 255. Both are ready and I will raise them once this lands.This replaces #6841, which bundled all three changes together.