This issue is to propose the addition of a new style rule that would check for vertical alignment of collection types (such as with arrays, dictionaries, and sets).
The proposed rule would ensure that collections that span multiple lines would be vertically aligned on the first character, or on colons for dictionaries.
Triggering examples
// ❌ Coordinates not aligned on first character
let coordinates = [
CLLocationCoordinate2D(latitude: 0, longitude: 33),
CLLocationCoordinate2D(latitude: 0, longitude: 66),
CLLocationCoordinate2D(latitude: 0, longitude: 99)
]
// ❌ Strings not aligned on first character or on colons
let meals = [
"breakfast": "oatmeal",
"lunch": "sandwich",
"dinner": "burger"
]
// ❌ Integers not aligned on first character
var evenNumbers: Set<Int> = [
2,
4,
6
]
Non-triggering examples
// ✅ Dictionary keys aligned on first character
let colorDictionary: [NSNumber: UIColor] = [
0: .clear,
5: .white,
10: .green,
15: .yellow,
20: .red
]
// ✅ Dictionary keys aligned on colon
let colorDictionary: [String: UIColor] = [
"mild": .green,
"moderate": .yellow,
"severe": .red
]
✅ Array of strings aligned on first character
let pets = [
"cat",
"dog",
"fish"
]
No, I don't believe the rule should be configurable.
The proposed rule should be enabled by default to promote consistency in alignment, which is enforced through other rules. I'm open to this being different though.
I think this should be configurable on how to validate dictionaries: aligning colons x the first character.
I'd like to give this one a try if no one else is working on it.
@daltonclaybrook as far as I know no one is working on this. Feel free to grab it 🎉
Let me now if you have any issues! Looking how the other vertical alignment rules are implemented is probably a good start.
Hey - looks like you forgot to add a T:* label - could you please add one?
Most helpful comment
I think this should be configurable on how to validate dictionaries: aligning colons x the first character.