realm / realm/SwiftLint

Bug: `indentation_width` rule does not detect incorrectly indented closing braces

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

Nobody has claimed this yet.

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

Description

New Issue Checklist

Describe the bug

The indentation_width rule fails to detect when a closing brace } is indented incorrectly (doesn't match the indentation of its opening statement). The rule correctly detects indentation issues on regular statements but misses closing braces that are under-indented.

Steps to Reproduce

Run the following command:

echo 'import SwiftUI

struct TestView: View {
    var body: some View {
        VStack {
            Text("Hello")
        }
        .onTapGesture {
            if true {
                print("inside if")
        }
        }
    }
}' | swiftlint lint --no-cache --use-stdin --enable-all-rules
File structure explained:
import SwiftUI

struct TestView: View {
    var body: some View {
        VStack {
            Text("Hello")
        }
        .onTapGesture {
            if true {                    // Line 9: 12 spaces (3 levels)
                print("inside if")       // Line 10: 16 spaces (4 levels) ✓
        }                                // Line 11: 8 spaces (2 levels) ✗ WRONG - should be 12
        }                                // Line 12: 8 spaces (2 levels) ✓
    }
}

The closing } on line 11 (closing the if statement) has only 8 spaces of indentation, but it should have 12 spaces to match the if true { on line 9.

Expected behavior

SwiftLint should report an indentation_width violation on line 11:

<nopath>:11:1: warning: Indentation Width Violation: Code should be indented using one tab or 4 spaces (indentation_width)

Actual behavior

No violation is reported for line 11. The output only shows other violations (explicit_acl, file_header, etc.) but no indentation_width violation for the incorrectly indented closing brace.

Proof that the rule works for other cases

The rule DOES correctly detect indentation issues on regular statements:

echo 'import SwiftUI

struct TestView: View {
    var body: some View {
        if true {
          print("wrong indent")
        }
    }
}' | swiftlint lint --no-cache --use-stdin --enable-all-rules

Output includes:

<nopath>:6:1: error: Indentation Width Violation: Code should be indented using one tab or 4 spaces (indentation_width)

This proves the rule is active and working, but it specifically misses closing braces.

Environment

  • SwiftLint version: 0.63.2
  • Installation method: Pre-built binary
  • Xcode version: 16.x
  • macOS version: macOS 15.x (Sequoia)

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 running the provided swiftlint lint command with the reproducing Swift input, then trace the indentation_width rule's handling of closing braces. Done means the incorrectly indented closing brace on line 11 produces the expected indentation_width violation while existing statement checks continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.