Skip to content

Enforce whitespace checks #89

Closed
Closed

Description

@nehasingh2293
  • 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 comment

Not 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 = 2

Not 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 : b

Not 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

Activity

  1. self-assigned this
    on Jul 6, 2015
  2. added this to the Sprint 4 milestone on Jul 10, 2015
  3. added 6 commits that reference this issue on Jul 15, 2015
  4. added a commit that references this issue on Jul 28, 2015
  5. git-commit commented on May 18, 2016

    @git-commit

    Could you change the rule for [function-whitespace] to not apply when at the top of a class or the very bottom?

    See this screenshot for an example of a in my opinion wrong linting:
    screen shot 2016-05-18 at 22 18 22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions