Function Name Whitespace

There should be consistent whitespace before and after function names and generic parameters.

  • Identifier: function_name_whitespace
  • Enabled by default: Yes
  • Supports autocorrection: Yes
  • Kind: style
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning
    generic_spacing no_space

Non Triggering Examples

func abc(lhs: Int, rhs: Int) -> Int {}
func <| (lhs: Int, rhs: Int) -> Int {}
func <|< <A>(lhs: A, rhs: A) -> A {}
func <| /* comment */ (lhs: Int, rhs: Int) -> Int {}
func <|< /* comment */ <A>(lhs: A, rhs: A) -> A {}
func <|< <A> /* comment */ (lhs: A, rhs: A) -> A {}
func <| /* comment */ <T> /* comment */ (lhs: T, rhs: T) -> T {}
//
// generic_spacing: no_space
//

func abc<T>(lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: leading_space
//

func abc <T>(lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: trailing_space
//

func abc<T> (lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: leading_space
//

func abc <T>(lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: leading_space
//

func abc /* comment */ <T> /* comment */ (lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: trailing_space
//

func abc /* comment */ <T> /* comment */ (lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: leading_trailing_space
//

func abc <T> (lhs: Int, rhs: Int) -> Int {}

func /* comment */ abc(lhs: Int, rhs: Int) -> Int {}
func /* comment */  abc(lhs: Int, rhs: Int) -> Int {}
func abc /* comment */ (lhs: Int, rhs: Int) -> Int {}
//
// generic_spacing: no_space
//

func abc /* comment */ <T>(lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: no_space
//

func abc<T> /* comment */ (lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: no_space
//

func abc /* comment */ <T> /* comment */ (lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: no_space
//

func foo<
   T
>(
   param1: Int,
   param2: Bool,
   param3: [String]
) { }

//
// generic_spacing: leading_trailing_space
//

func foo <
T
> (
    param1: Int,
    param2: Bool,
    param3: [String]
) { }

//
// generic_spacing: leading_trailing_space
//

func foo /* comment */ <
T
> (
    param1: Int,
    param2: Bool,
    param3: [String]
) { }

Triggering Examples

func  name(lhs: A, rhs: A) -> A {}
func name (lhs: A, rhs: A) -> A {}
func  name (lhs: A, rhs: A) -> A {}
func <|(lhs: Int, rhs: Int) -> Int {}
func <|<<A>(lhs: A, rhs: A) -> A {}
func <|  (lhs: Int, rhs: Int) -> Int {}
func <|<  <A>(lhs: A, rhs: A) -> A {}
func <|/* comment */  (lhs: Int, rhs: Int) -> Int {}
func <|</* comment */  <A>(lhs: A, rhs: A) -> A {}
func <|< <A>/* comment */  (lhs: A, rhs: A) -> A {}
func name <T>(lhs: Int, rhs: Int) -> Int {}
//
// generic_spacing: no_space
//

func name /* comment */  <T>  /* comment */  (lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: no_space
//

func name /* comment */ /* comment */  <T>  /* comment */  (lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: no_space
//

func foo<
   T
> (
   param1: Int,
   param2: Bool,
   param3: [String]
) { }

//
// generic_spacing: no_space
//

func foo <
   T
>(
   param1: Int,
   param2: Bool,
   param3: [String]
) { }

//
// generic_spacing: no_space
//

func foo <
  T
> (
   param1: Int,
   param2: Bool,
   param3: [String]
) { }

//
// generic_spacing: leading_space
//

func abc <T> (lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: leading_space
//

func foo <
T
> (
    param1: Int,
    param2: Bool,
    param3: [String]
) { }

//
// generic_spacing: trailing_space
//

func abc <T> (lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: trailing_space
//

func foo <
T
> (
    param1: Int,
    param2: Bool,
    param3: [String]
) { }

//
// generic_spacing: leading_trailing_space
//

func abc<T> (lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: leading_trailing_space
//

func abc <T>(lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: leading_trailing_space
//

func abc<T>(lhs: Int, rhs: Int) -> Int {}

//
// generic_spacing: leading_trailing_space
//

func foo /* comment */  <
T
>  (
    param1: Int,
    param2: Bool,
    param3: [String]
) { }