-
Notifications
You must be signed in to change notification settings - Fork 48
Enforce whitespace checks #89
Copy link
Copy link
Closed
Description
- one blank line between methods
- whitespace around operators when defining them
Preferred
prefix operator += {}Not Preferred
prefix operator +-+ {}
prefix operator ** {}- only one space between opening construct and
{brace (except for compound assignment operators+=)
Preferred
func helloWorld {
// do something
}Not Preferred
func helloWorld{
// do something
}
class hello {
var message: String
}- one space after
//in comments
Preferred
// this is a commentNot Preferred
//this is a comment- start and end multi-line comments with a single space
Preferred
/* This is a
multiline comment */Not Preferred
/*This is a
multiline comment*/- Colon directly after identifier, then space and type name
Preferred
var x: Int = 2Not Preferred
var x : Int
var y: String- Colon directly after key type, then space and value for dictionary types
Preferred
var x = [ 'key1': 1, 'key2': 2 ]
var y: [ Int: String ]Not Preferred
var x = [ 'key1' : 1, 'key2': 3]
var y: [ Int : String ]- Colon directly after case label, then space and statements
Preferred
switch character {
case "a": doSomething(a);
default: alert();
}Not Preferred
switch character {
case "a" : doSomething(a);
default: alert();
}- Colon directly after class/struct/protocol/extension name, followed by space, followed by type inheritance list
Preferred
class ClassName: BaseClass {
}
struct StructName: BaseStruct {
}
protocol ProtocolName: AnotherProtocol {
}
extension TypeName: ProtocolName {
}Not Preferred
class ClassName : BaseClass {
}
struct StructName: BaseStruct {
}
protocol ProtocolName:AnotherProtocol {
}
extension TypeName : ProtocolName {
}- Single space before and after colon in a conditional expression
Preferred
var x = condition ? a : bNot Preferred
var x = condition ? a: b
var x = condition ? a : b- Tuple name, followed by colon, followed by a space, followed by value
Preferred
var y = (key: 1, value: 2)Not Preferred
var y = (key:1, value : 2)- Colon directly after typeName, followed by a space in generic parameter clauses
Preferred
func someFunction<T: SomeClass, U: SomeProtocol>(someT: T, someU: U) {
}Not Preferred
func someFunction<T : SomeClass, U:SomeProtocol>(someT: T, someU: U) {
}- Check for a space before and after '->' in function and closure declarations
- Check for a space before and after '->' in subscripts
- Check for a space before and after '->' in function types
Reactions are currently unavailable