realm / realm/SwiftLint

opening_brace rule breaks Xcode indentation for multiline function declarations

Open
#3,735 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

New Issue Checklist
Describe the bug

If a function declaration has its opening brace on the same line as the func, Xcode is smart enough to indent one "tab" for the body of the function.

However, if the function would span past the 120 character line length limit, if the opening brace is on the same line as the return value or other arguments, Xcode tries to indent by two "tab"s.

This is super frustrating and I've found myself fighting the indentation to resolve the lint violation.

Is it possible to either customize the rule or extend it to handle this case better?

My preferred behavior would be that multiline functions, guard and if statements would have their opening brace on a newline.

Current:

func shortFunctionName(shortParameterName: ShortType) -> ReturnValue {
    // Xcode wants to indent to here
}

func someReallyLongFunctionName(
    someReallyLongParameterName: SomeType,
    anotherReallyLongParameterName: AnotherType)
    -> ReturnValue {
        // Xcode wants to indent to here
}

Preferred:

func shortFunctionName(shortParameterName: ShortType) -> ReturnValue {
    // Xcode wants to indent to here
}

func someReallyLongFunctionName(
    someReallyLongParameterName: SomeType,
    anotherReallyLongParameterName: AnotherType)
    -> ReturnValue
{
    // Xcode wants to indent to here
}

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 by locating the opening_brace rule and reviewing how it handles multiline function declarations, including any existing configuration and tests. Compare the current and preferred examples, then define and verify the expected brace placement for multiline functions and related guard or if statements.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.