Skip to content

Fix statement_position for guard else without whitespace#6543

Open
theamodhshetty wants to merge 1 commit intorealm:mainfrom
theamodhshetty:codex/fix-statement-position-guard-else
Open

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

Conversation

@theamodhshetty
Copy link
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

2 Warnings
⚠️ This PR may need tests.
⚠️ This PR introduced a violation in Firefox: /firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksViewController.swift:235:78: Warning: Else and catch should be on the same line, one space after the previous declaration (statement_position)
19 Messages
📖 Building this branch resulted in a binary size of 27358.93 KiB vs 27357.74 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.33 s vs 0.33 s on main (0% slower).
📖 Linting Alamofire with this PR took 0.42 s vs 0.42 s on main (0% slower).
📖 Linting Brave with this PR took 2.43 s vs 2.44 s on main (0% faster).
📖 Linting DuckDuckGo with this PR took 9.78 s vs 9.8 s on main (0% faster).
📖 Linting Firefox with this PR took 4.48 s vs 4.46 s on main (0% slower).
📖 Linting Kickstarter with this PR took 2.87 s vs 2.88 s on main (0% faster).
📖 Linting Moya with this PR took 0.23 s vs 0.2 s on main (15% slower).
📖 Linting NetNewsWire with this PR took 0.95 s vs 0.95 s on main (0% slower).
📖 Linting Nimble with this PR took 0.34 s vs 0.33 s on main (3% slower).
📖 Linting PocketCasts with this PR took 2.68 s vs 2.7 s on main (0% faster).
📖 Linting Quick with this PR took 0.25 s vs 0.24 s on main (4% slower).
📖 Linting Realm with this PR took 0.96 s vs 0.97 s on main (1% faster).
📖 Linting Sourcery with this PR took 0.7 s vs 0.67 s on main (4% slower).
📖 Linting Swift with this PR took 1.39 s vs 1.38 s on main (0% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 3.84 s vs 3.86 s on main (0% faster).
📖 Linting VLC with this PR took 0.5 s vs 0.5 s on main (0% slower).
📖 Linting Wire with this PR took 6.89 s vs 6.88 s on main (0% slower).
📖 Linting WordPress with this PR took 4.53 s vs 4.5 s on main (0% slower).

Generated by 🚫 Danger

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

2 participants