Skip to content

Don't flag color components of Color and NSColor initializers - #6841

Open
lechuckcaptain wants to merge 1 commit into
realm:mainfrom
lechuckcaptain:no-magic-numbers-colour-initializers
Open

Don't flag color components of Color and NSColor initializers#6841
lechuckcaptain wants to merge 1 commit into
realm:mainfrom
lechuckcaptain:no-magic-numbers-colour-initializers

Conversation

@lechuckcaptain

@lechuckcaptain lechuckcaptain commented Jul 28, 2026

Copy link
Copy Markdown

Summary

  • no_magic_numbers exempts the color-component arguments of a UIColor initializer, but the
    check hardcoded that one type name, so SwiftUI's Color and AppKit's NSColor got no exemption
    at all. All three are now recognised, and the opacity label is accepted alongside alpha.
  • AppKit encodes the color space in the label of the first component, so recognising the type name
    alone was not enough: NSColor(srgbRed: 0.1, green: 0.42, blue: 0.7, alpha: 1) would have had
    its last three components exempted and the first still reported. The calibratedRed,
    deviceRed, srgbRed, calibratedWhite, deviceWhite, genericGamma22White, calibratedHue
    and deviceHue variants are covered too, as are the CMYK components of
    deviceCyan:magenta:yellow:black:alpha:.
  • The exemption also required the literal to be the immediate argument, so UIColor(red: 0.6, …)
    was exempt while UIColor(red: 0x19 / 255, …) was not. The enclosing argument is now found by
    walking up through arithmetic, parentheses and numeric conversions, bailing out on anything else
    so an exemption cannot leak past the argument it was granted for.
    Every literal is still judged by its own label, so an unrecognised label is exempted for nothing but
    itself: in Wire's UIColor(rgb: 0x33373A, alpha: 0.16) the rgb: value stays reported while
    alpha: is exempt, since 0.16 is a color component whatever its sibling happens to be. There is
    a triggering example pinning that.

Validation

  • swift test --filter NoMagicNumbersRuleGeneratedTests passes, as do the RuleDocumentation,
    DefaultRuleConfiguration, RuleNameConsistency and Example suites. No existing example was
    edited, reordered or removed; the manual bit-packing example Int(r * 255) << 16 and
    Color.primary.opacity(isAnimate ? 0.1 : 1.5) still trigger.
  • swift run swiftlint --strict clean on the changed file.
  • OSS-check: 861 false positives removed across 18 public projects, 0 introduced.

@SwiftLintBot

SwiftLintBot commented Jul 28, 2026

Copy link
Copy Markdown
1 Warning
⚠️ This PR may need tests.
880 Messages
📖 Building this branch resulted in a binary size of 28443.1 KiB vs 28425.49 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.11 s vs 0.15 s on main (26% faster).
📖 Linting Alamofire with this PR took 0.12 s vs 0.13 s on main (7% faster).
📖 Linting Brave with this PR took 0.55 s vs 0.52 s on main (5% slower).
📖 Linting DuckDuckGo with this PR took 2.22 s vs 2.21 s on main (0% slower).
📖 Linting Firefox with this PR took 0.9 s vs 0.87 s on main (3% slower).
📖 Linting Kickstarter with this PR took 0.58 s vs 0.6 s on main (3% faster).
📖 Linting Moya with this PR took 0.11 s vs 0.1 s on main (9% slower).
📖 Linting NetNewsWire with this PR took 0.22 s vs 0.23 s on main (4% faster).
📖 Linting Nimble with this PR took 0.15 s vs 0.15 s on main (0% slower).
📖 Linting PocketCasts with this PR took 0.72 s vs 0.68 s on main (5% slower).
📖 Linting Quick with this PR took 0.1 s vs 0.1 s on main (0% slower).
📖 Linting Realm with this PR took 0.34 s vs 0.32 s on main (6% slower).
📖 Linting Sourcery with this PR took 0.17 s vs 0.19 s on main (10% faster).
📖 Linting Swift with this PR took 0.34 s vs 0.35 s on main (2% faster).
📖 Linting SwiftLintPerformanceTests with this PR took 3.74 s vs 3.76 s on main (0% faster).
📖 Linting VLC with this PR took 0.23 s vs 0.2 s on main (15% slower).
📖 Linting Wire with this PR took 1.16 s vs 1.13 s on main (2% slower).
📖 Linting WordPress with this PR took 0.76 s vs 0.76 s on main (0% slower).
📖 This PR fixed a violation in Aerial: /Aerial/Source/Views/PrefPanel/DisplayView.swift:62:51: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Views/PrefPanel/DisplayView.swift:63:47: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Views/PrefPanel/DisplayView.swift:69:51: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Views/PrefPanel/DisplayView.swift:70:47: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Aerial: /Aerial/Source/Views/PrefPanel/DisplayView.swift:166:47: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/App/BraveWidgets/LockScreenFavoriteWidget.swift:128:26: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Crypto/TransactionConfirmations/SaferSignTransactionView.swift:187:41: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Crypto/Accounts/AccountsView.swift:303:30: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Crypto/Onboarding/OnboardingNetworkSelectionView.swift:393:32: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:28:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:28:19: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:29:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:29:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:30:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:30:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:35:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:35:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:36:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:36:22: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:37:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:37:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:48:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:48:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:49:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:49:22: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:50:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:50:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:55:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:55:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:56:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:56:22: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:57:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:57:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:68:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:68:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:69:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:69:22: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:70:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:70:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:75:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:75:19: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:76:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:76:22: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:77:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:77:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:88:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:88:19: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:89:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:89:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:90:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:90:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:95:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:95:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:96:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:96:22: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:97:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:97:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:110:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:110:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:111:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:111:22: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:112:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:112:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:117:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:117:19: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:118:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:118:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:119:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:119:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:129:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:129:19: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:130:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:130:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:131:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:131:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:136:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:136:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:137:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:137:22: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:138:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:138:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:151:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:151:19: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:152:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:152:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:153:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:153:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:164:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:164:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:165:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:165:22: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:166:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:166:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:171:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:171:19: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:172:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:172:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:173:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:173:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:182:10: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:182:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:183:12: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:183:17: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:184:11: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:184:17: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:193:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:193:19: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:194:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:194:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:195:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:195:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:200:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:200:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:201:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:201:22: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:202:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:202:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:213:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:213:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:214:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:214:22: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:215:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:215:21: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:220:14: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:220:20: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:221:16: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:221:22: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
📖 This PR fixed a violation in Brave: /ios/brave-ios/Sources/BraveWallet/Extensions/WalletColors.swift:222:15: Warning: Magic numbers should be replaced by named constants (no_magic_numbers)
⚠️ Danger found 880 violations with this PR. Due to GitHub's max issue comment size, the number shown has been truncated to 147.

Generated by 🚫 Danger

@lechuckcaptain
lechuckcaptain force-pushed the no-magic-numbers-colour-initializers branch 2 times, most recently from 77d5564 to a317a2a Compare July 28, 2026 21:47
`no_magic_numbers` already exempts the component arguments of a `UIColor`
initializer, but the check hardcoded that single type name, so SwiftUI's `Color`
and AppKit's `NSColor` got no exemption at all. Recognise all three, and accept
the `opacity` label alongside `alpha`, since SwiftUI spells it differently.

AppKit encodes the color space in the label of the first component, so cover the
`calibratedRed`, `deviceRed`, `srgbRed`, `calibratedWhite`, `deviceWhite`,
`genericGamma22White`, `calibratedHue` and `deviceHue` variants as well as the
`deviceCyan:magenta:yellow:black:alpha:` components. Recognising the type name
alone would have left the first component of such a call reported while the rest
were not.

The exemption also required the literal to be the *immediate* argument, so
`UIColor(red: 0.6, ...)` was exempt while `UIColor(red: 0x19 / 255, ...)` was
not: there the literal's parent is the division, not the labelled argument. Walk
up through arithmetic, parentheses and numeric conversions to find the enclosing
argument instead, and bail out on anything else so an exemption granted for one
argument cannot leak past it.

That boundary is what keeps the existing manual bit-packing example
`Int(r * 255) << 16` flagged, and `Color(...).opacity(0.42)` too, since in
neither case is the literal inside a color initializer's argument list.

Every literal remains judged by its own label, so an unrecognised label is
exempted for nothing but itself: `UIColor(rgb: 0x33373A, alpha: 0.16)` keeps
reporting the `rgb:` value while exempting `alpha:`, which is a color component
whatever its sibling happens to be.
@lechuckcaptain
lechuckcaptain force-pushed the no-magic-numbers-colour-initializers branch from a317a2a to 14d590a Compare August 4, 2026 16:05
@lechuckcaptain
lechuckcaptain marked this pull request as ready for review August 4, 2026 20:57
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.

2 participants