Skip to content

statement_position rule triggers for missing space before else in if stmt, but not in guard #6153

Closed

Description

@lukaskollmer

New Issue Checklist

Bug Description

A clear and concise description of what the bug is. Ideally, provide a small (but compilable) example code snippet that
can be used to reproduce the issue.

guard foo()else { return } // This should trigger a violation, but doesn't

if foo() {
}else { // This triggers a violation (statement_position)
}

Mention the command or other SwiftLint integration method that caused the issue. Include stack traces or command output.

$ swiftlint test.swift
Linting Swift files at paths test.swift
Linting 'test.swift' (1/1)
/Users/lukas/temp/test.swift:4:1: 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: 0.59.1
  • Xcode version Xcode 16.4 Build version 16F6
  • Installation method used Homebrew
  • Configuration file: none (using implicit default config)

Activity

  1. added
    bug
    on Jul 3, 2025
  2. theamodhshetty commented on Mar 16, 2026

    @theamodhshetty
    Contributor

    Opened #6543 for this. The rule was only checking else/catch after a closing brace, so guard foo()else never matched. I added a small guard-specific matcher, wired it into autocorrect, and covered it with the generated rule examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions