SwiftLint
SwiftLint copied to clipboard
Create a rule enforcing colon position for dictionaries
Not sure if this is possible, but i'd love a rule that enforces colon position for dictionaries, I like dictionaries to be defined as [Key : Value] with a space on either side of the colon, this rule could be for dictionary instances and also for dictionary type definitions (e.g [String : AnyObject]).
Would love this too.
Personally, I see String: Int as 'string is of type Int' rather than String maps to Int. A separation between the two would be great.
I totally agree we should have a rule for the colon position on dictionaries, but I'm not sure if it should be [Key : Value]. I personally prefer [Key: Value] which is what the GitHub code style suggests and how Apple itself is writing on their documentation.
Perhaps then it should be configurable?
@ceeK: That would be ideal! Though it would be cool to agree on a default as well
Yep, and on that point, I think if Apple + Github style guide has it Key: Value, then that should be the default.
I agree, configurable with key: value as the default.
related: https://github.com/realm/SwiftLint/issues/637
Sorry, but I don't understand, why it was closed.
The apply_to_dictionaries parameter of the colon rule affects only dictionary contents, but not the dictionary type declaration (as is described in the feature proposal).
To elaborate, assume we have this code:
let dict: [String : String] = ["string" : "string"]
colon with apply_to_dictionaries: true produces this formatting:
let dict: [String: String] = ["string": "string"]
colon with apply_to_dictionaries: false produces this:
let dict: [String: String] = ["string" : "string"]
Whereas the feature proposal requires an opportunity to produce this:
let dict: [String : String] = ["string" : "string"]
Or did I miss something?
If there's another way to achieve that, please let me know!
+1 Would be nice to have such rule
The format requested by this issue is indeed not covered by the existing colon rule.