Skip to content

Extend trailing_comma rule to support function parameters and tuple elements #6500

@VentanYu

Description

@VentanYu

New Issue Checklist

Feature or Enhancement Proposal

Extend the trailing_comma rule to optionally enforce trailing commas in:

  • Function parameter lists (declarations and calls)
  • Tuple types and values
  • Closure parameter lists

Configuration

The rule should maintain backward compatibility while adding these new capabilities:

trailing_comma:
  mandatory_comma: true  # existing option (default: false)
  include_function_parameters: true  # new option (default: false)
  include_tuples: true  # new option (default: false)
  include_closures: true  # new option (default: false)

Examples

Non Triggering Examples:

// include_function_parameters: true
func fetchUser(
    id: Int,
    from cache: Cache,
) async throws -> User

// include_function_parameters: true
fetchUser(
    id: 42,
    from: memoryCache,
)

// include_tuples: true
typealias Pair = (
    String,
    Int,
)

// include_tuples: true
let person = (
    name: "John",
    age: 30,
)

// include_closures: true
let handler = { (
    success: Bool,
    error: Error?,
) in
    // handle
}

Triggering Examples:

// include_function_parameters: true
func fetchUser(
    id: Int,
    from cache: Cache
) async throws -> User

// include_function_parameters: true
fetchUser(
    id: 42,
    from: memoryCache
)

// include_tuples: true
typealias Pair = (
    String,
    Int)

// include_tuples: true
let person = (
    name: "John",
    age: 30
)

// include_closures: true
let handler = { (
    success: Bool,
    error: Error?↓
) in
    // handle
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIdeas for improvements of existing features and rules.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions