Skip to content

Bug: indentation_width rule does not detect incorrectly indented closing braces #6498

Description

@windaishi

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected and reproducible misbehavior.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions