SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

no_magic_number - Ignore UIColor initializers

Open LowAmmo opened this issue 2 years ago • 0 comments

New Issue Checklist

New rule request

Requesting another enhancement to "no_magic_numbers", where it will ignore UIColor definitions.

Since the nature of definiting a color is going to have some "magic numbers", I think it would make sense to just ignore the values -

static let grayColor: UIColor = #colorLiteral(red: 0.7019607843, green: 0.7019607843, blue: 0.7019607843, alpha: 1)
let myColor: UIColor = UIColor(red: 0.6, green: 1.0, blue: 0.2, alpha: 0.52)
let yourColor: UIColor = UIColor(hue: 0.9, saturation: 0.6, brightness: 0.333334, alpha: 1.0)

(including all other UIColor constructors

I don't think this needs to be an "opt-in" configuration...I would think most people would want this by default...but not opposed to it being an opt-in rule.

Hopefully that makes sense!

-Thanks!

LowAmmo avatar Aug 17 '23 16:08 LowAmmo