realm / realm/SwiftLint

`statement_position` fails on one-line `catch`

Open
#4,632 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

New Issue Checklist
Describe the bug

Assuming uncuddled_else, the following passes validation:

do {
    x
}
catch {
    y
}

But the following fails validation:

do { x }
catch { y }

This is inconsistent and should be fixed. One-line statements are very beneficial and shouldn't be punished.

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint test.swift
Linting Swift files at paths test.swift
Linting 'test.swift' (1/1)
test.swift:1:8: warning: Statement Position Violation: Else and catch should be on the same line, one space after 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.50.1
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? brew
  • Paste your configuration file:
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

Reproduce the report with the statement_position configuration in test.swift, comparing the multiline and one-line do/catch examples under uncuddled_else. Trace the statement_position rule and its tests, then verify that both forms are handled consistently without the reported violation.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.