Swiftlint: different length assignments "=" on the same column

Created on 25 Feb 2019  路  7Comments  路  Source: realm/SwiftLint

New Issue Checklist

New rule request

Please describe the rule idea, format
this issue's title as Rule Request: equation sign in same column and describe:

  1. Why should this rule be added? Share links to existing discussion about what
    the community thinks about this.

rule will provide better code readability

  1. Provide several examples of what _would_ and _wouldn't_ trigger violations.

this should trigger violation

var first = ""  
var longVariable = ""

this should NOT trigger violation

var first        = ""  
var longVariable = ""
  1. Should the rule be configurable, if so what parameters should be configurable?

probably you should have possibility to set offset threshold to not move short names when one is very very long

  1. Should the rule be opt-in or enabled by default? Why?
    See README.md for guidelines on when to mark a rule as opt-in.

this can be in my opinion enabled by default as it not violates

rule-request

Most helpful comment

this should definitely be opt-in

All 7 comments

this should definitely be opt-in

well I can agree that not everyone will like such looking code so opt-in is ok for me,

this rule could be useful for auto fix feature, for rapid fix of old code as it only changes spacing

@nysander feel free to open a PR!

well I'm new to swift and this rule I've learned when programming in PHP using manually so unfortunately atm I have no idea where to start how to do such rule for swiftlint. but maybe with some hints I can try

as I've tested my proposal is in conflict with:

  • "colon" rule: "Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)"
  • "operator_usage_whitespace" rule: "Operator Usage Whitespace Violation: Operators should be surrounded by a single whitespace when they are being used. (operator_usage_whitespace)"

few examples in which styling code makes conflicts:

    @IBOutlet var titleLabel:       UILabel!
    @IBOutlet var locationLabel:    UILabel!
    @IBOutlet var dateLabel:        UILabel!
    @IBOutlet var descriptionLabel: UILabel!

    titleLabel.text       = item.title
    locationLabel.text    = item.location?.name
    descriptionLabel.text = item.itemDescription

maybe the solution could be optional configuration for those rules to allow such styling?

Hi @nysander Do you know any tool that would automate this alignment? Iv'e used to use https://github.com/qfish/XAlign in the past, but from Issues it seems that it's not working anymore. On the other hand: https://github.com/nicklockwood/SwiftFormat/issues/359

I've used phpcsfixer long time ago. I do not remember if it has this feature but I liked to have my php code styled this way.

Was this page helpful?
0 / 5 - 0 ratings