trailing_comma - ApplebaumIan/BitbucketAPI GitHub Wiki

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)"↓,])