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

Rule request: Vertical alignment of collection types #2326

Closed
2 tasks done
captainbarbosa opened this issue Jul 31, 2018 · 4 comments · Fixed by #2392
Closed
2 tasks done

Rule request: Vertical alignment of collection types #2326

captainbarbosa opened this issue Jul 31, 2018 · 4 comments · Fixed by #2392
Labels
rule-request Requests for a new rules.

Comments

@captainbarbosa
Copy link

New Issue Checklist

Rule Request

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).

  1. Why should this rule be added?

The proposed rule would ensure that collections that span multiple lines would be vertically aligned on the first character, or on colons for dictionaries.

  1. Provide several examples of what would and wouldn't trigger violations.

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"
]
  1. Should the rule be configurable, if so what parameters should be configurable?

No, I don't believe the rule should be configurable.

  1. Should the rule be opt-in or enabled by default? Why?

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.

@realm-probot realm-probot bot added the O:User label Jul 31, 2018
@marcelofabri marcelofabri added the rule-request Requests for a new rules. label Aug 5, 2018
@marcelofabri
Copy link
Collaborator

I think this should be configurable on how to validate dictionaries: aligning colons x the first character.

@daltonclaybrook
Copy link
Contributor

I'd like to give this one a try if no one else is working on it.

@marcelofabri
Copy link
Collaborator

@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.

@realm-probot
Copy link

realm-probot bot commented Sep 11, 2018

Hey - looks like you forgot to add a T:* label - could you please add one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule-request Requests for a new rules.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants