Tags: airbnb/swift
Tags
Update trailing commas rule to apply to all multi-element comma-separ… …ated lists (#323) #### Summary This PR updates the trailing commas rule to apply to all comma-separated lists, including function calls and function declarations. ```swift let terrestrialPlanets = [ mercury, venus, earth, mars, ] func buildSolarSystem( innerPlanets: [Planet], outerPlanets: [Planet], ) { ... } buildSolarSystem( innertPlanets: terrestrialPlanets, outerPlanets: gasGiants, ) ``` This PR also refines the rule to omit the trailing comma if the list only contains a single element. We feel this is especially the right choice in function calls with only a single argument, where the trailing commas adds unnecessary noise: ```swift // WRONG let planetsWithLife = [ earth, ] func buildSolarSystem( _ planets: [Planet], ) buildSolarSystem( terrestrialPlanets + gasGiants, ) // RIGHT let planetsWithLife = [ earth ] func buildSolarSystem( _ planets: [Planet] ) { ... } buildSolarSystem( terrestrialPlanets + gasGiants ) ``` <!--- required --->