Skip to content

Fix statement_position for guard else without whitespace#6543

Merged
SimplyDanny merged 1 commit intorealm:mainfrom
theamodhshetty:codex/fix-statement-position-guard-else
Apr 10, 2026
Merged

Fix statement_position for guard else without whitespace#6543
SimplyDanny merged 1 commit intorealm:mainfrom
theamodhshetty:codex/fix-statement-position-guard-else

Conversation

@theamodhshetty
Copy link
Copy Markdown
Contributor

Summary

  • detect guard foo()else in statement_position
  • autocorrect it to guard foo() else
  • add regression examples and a changelog entry

The rule currently only looks for else and catch after a closing brace, so the guard form from #6153 slips through. This keeps the existing brace-based matching in place and adds a small guard-specific matcher that only fires when else is tokenized as a keyword.

Testing

  • swift test --filter StatementPositionRuleGeneratedTests
  • swift test --filter StatementPositionRuleTests
  • ./.build/debug/swiftlint lint Source/SwiftLintBuiltInRules/Rules/Style/StatementPositionRule.swift CHANGELOG.md --strict

@SwiftLintBot
Copy link
Copy Markdown

SwiftLintBot commented Mar 16, 2026

1 Warning
⚠️ This PR may need tests.
19 Messages
📖 Building this branch resulted in a binary size of 27477.29 KiB vs 27476.09 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.3 s vs 0.31 s on main (3% faster).
📖 Linting Alamofire with this PR took 0.39 s vs 0.39 s on main (0% slower).
📖 Linting Brave with this PR took 2.47 s vs 2.42 s on main (2% slower).
📖 Linting DuckDuckGo with this PR took 10.29 s vs 10.22 s on main (0% slower).
📖 Linting Firefox with this PR took 4.57 s vs 4.54 s on main (0% slower).
📖 Linting Kickstarter with this PR took 2.95 s vs 2.93 s on main (0% slower).
📖 Linting Moya with this PR took 0.2 s vs 0.2 s on main (0% slower).
📖 Linting NetNewsWire with this PR took 0.98 s vs 0.95 s on main (3% slower).
📖 Linting Nimble with this PR took 0.3 s vs 0.31 s on main (3% faster).
📖 Linting PocketCasts with this PR took 2.74 s vs 2.74 s on main (0% slower).
📖 Linting Quick with this PR took 0.21 s vs 0.2 s on main (4% slower).
📖 Linting Realm with this PR took 0.94 s vs 0.95 s on main (1% faster).
📖 Linting Sourcery with this PR took 0.68 s vs 0.7 s on main (2% faster).
📖 Linting Swift with this PR took 1.41 s vs 1.39 s on main (1% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 3.86 s vs 3.87 s on main (0% faster).
📖 Linting VLC with this PR took 0.5 s vs 0.52 s on main (3% faster).
📖 Linting Wire with this PR took 7.03 s vs 6.97 s on main (0% slower).
📖 Linting WordPress with this PR took 4.56 s vs 4.55 s on main (0% slower).

Generated by 🚫 Danger

Copy link
Copy Markdown
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@SimplyDanny SimplyDanny force-pushed the codex/fix-statement-position-guard-else branch from 74f4d5d to cf8d241 Compare April 10, 2026 19:35
@SimplyDanny SimplyDanny enabled auto-merge (squash) April 10, 2026 19:35
@SimplyDanny SimplyDanny merged commit bd662b7 into realm:main Apr 10, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants