Skip to content

Update trailing commas rule to apply to all comma-separated lists #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 7, 2025

Conversation

calda
Copy link
Member

@calda calda commented Jul 21, 2025

Summary

This PR updates the trailing commas rule to apply to all comma-separated lists, including function calls and function declarations.

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:

// WRONG
let planetsWithLife = [
  earth,
]

func buildSolarSystem(
  _ planets: [Planet],
)

buildSolarSystem(
  terrestrialPlanets + gasGiants,
)

// RIGHT
let planetsWithLife = [
  earth
]

func buildSolarSystem(
  _ planets: [Planet]
) { ... }

buildSolarSystem(
  terrestrialPlanets + gasGiants
)

@calda calda enabled auto-merge (squash) August 7, 2025 16:34
@calda calda disabled auto-merge August 7, 2025 16:34
@calda calda merged commit a702f58 into master Aug 7, 2025
4 checks passed
@calda calda deleted the cal--trailing-commas branch August 7, 2025 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant