realm / realm/SwiftLint

Extend trailing_comma rule to support function parameters and tuple elements

Open
#6,500 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

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
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing trailing_comma rule and its configuration handling. Extend the rule to cover function parameter lists, tuple types and values, and closure parameter lists while preserving current defaults; done means the proposed options and triggering/non-triggering examples behave as specified.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.