statement_position fails for `if` inside `if`
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
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 versionto 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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