realm / realm/SwiftLint

statement_position fails for `if` inside `if`

Open
#3,928 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

statement_position with uncuddled_else is supposed to verify that else and if are on the same position. This check fails for ifs that are inside another if, such as in the following case:

if x {
}
else {
}

if x {}
else {}

if x {
    if x {} // swiftlint fails
    else {}
}
else {}
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint foo.swift
Linting Swift files at paths foo.swift
Linting 'foo.swift' (1/1)
foo.swift:10:11: warning: Statement Position Violation: Else and catch should be on the next line, with equal indentation to the previous declaration. (statement_position)
Done linting! Found 1 violation, 0 serious in 1 file.
Environment
  • SwiftLint version (run swiftlint version to be sure)? 0.47.0

  • Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew

  • Are you using nested configurations? no

  • Which Xcode version are you using (check xcodebuild -version)? Xcode 13.3, Build version 13E113

statement_position:
  statement_mode: uncuddled_else

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 reproducing the nested-if example in foo.swift with SwiftLint 0.47.0 and the shown statement_position uncuddled_else configuration. Trace the statement_position rule's handling of nested if statements, then add or update coverage so the example no longer reports a violation while the existing top-level cases retain their expected behavior.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.