Closed saagarjha closed 7 years ago
Thank you for this feedback
Another issue with spacing: operator functions. For example:
func ==(lhs: Foo, rhs: Foo) -> Bool {
return true
}
becomes
func == (lhs: Foo, rhs: Foo) -> Bool {
return true
}
It is a hard one, I'll try to find out.
While we're at it,
infix operator ?! : NilCoalescingPrecedence
becomes
infix operator ? ! : NilCoalescingPrecedence
which breaks code.
Is ?!
your custom operator or general library usage?
You can modify SwiftParser.swift and add ("?!", 2)
to line 27 "?" : []
to become
"?" : [("?!", 2)]
, than everything should works.
And I think this style is more consistence.
infix operator ?!: NilCoalescingPrecedence
Also found from Apple website,https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html
infix operator +-: AdditionPrecedence
extension Vector2D {
static func +- (left: Vector2D, right: Vector2D) -> Vector2D {
return Vector2D(x: left.x + right.x, y: left.y - right.y)
}
}
let firstVector = Vector2D(x: 1.0, y: 2.0)
let secondVector = Vector2D(x: 3.0, y: 4.0)
let plusMinusVector = firstVector +- secondVector
// plusMinusVector is a Vector2D instance with values of (4.0, -2.0)
Yes, it's a custom operator similar to the Nil Coalescing operator ??
.
As for the formatting of operators, I would tend to agree with you, except that Swift seems to put a space between operators and the colon–I think the one on Apple's website just hasn't been updated.
In addition, the example I gave above of
func == (lhs: Foo, rhs: Foo) -> Bool {
return true
}
appears to be correct behavior (both Swift and The Swift Programming Language use this formatting); please keep this as-is.
Finally, I did see your workaround, and I'll be using it, but I think we'll have to eventually come up with a better method for custom operators since they can incorporate basically any symbol characters. Maybe we could search for operator
and turn off the formatter temporarily?
Yes, the function style should add one space. I'll keep working on it.
And for the custom operator, I do have some plan about it. We should allow user to add, modify like preference.
The space issue is fix, we can keep going on in #112 with the custom operator.
Swimat is formatting this incorrectly:
Swimat doesn't remove the space before
queue:
for whatever reason. @Jintin could you look into it?