Skip to content

trailing_comma

Ian Applebaum edited this page Jun 13, 2020 · 1 revision

Trailing Comma

Trailing commas in arrays and dictionaries should be avoided/enforced.

  • Identifier: trailing_comma
  • Enabled by default: Enabled
  • Supports autocorrection: Yes
  • Kind: style
  • Analyzer rule: No
  • Minimum Swift compiler version: 3.0.0
  • Default configuration: warning, mandatory_comma: false

Non Triggering Examples

let foo = [1, 2, 3]
let foo = []
let foo = [:]
let foo = [1: 2, 2: 3]
let foo = [Void]()
let example = [ 1,
 2
 // 3,
]
foo([1: "\(error)"])

Triggering Examples

let foo = [1, 2, 3,]
let foo = [1, 2, 3, ]
let foo = [1, 2, 3   ,]
let foo = [1: 2, 2: 3, ]
struct Bar {
 let foo = [1: 2, 2: 3, ]
}
let foo = [1, 2, 3,] + [4, 5, 6,]
let example = [ 1,
2,
 // 3,
]
let foo = ["אבג", "αβγ", "🇺🇸",]
class C {
 #if true
 func f() {
 let foo = [1, 2, 3,]
 }
 #endif
}
foo([1: "\(error)",])
Clone this wiki locally