Skip to content

Avoid dropping inline comments in control_statement fixes#6545

Open
theamodhshetty wants to merge 1 commit intorealm:mainfrom
theamodhshetty:codex/fix-control-statement-inline-comments
Open

Avoid dropping inline comments in control_statement fixes#6545
theamodhshetty wants to merge 1 commit intorealm:mainfrom
theamodhshetty:codex/fix-control-statement-inline-comments

Conversation

@theamodhshetty
Copy link
Contributor

Summary

  • stop control_statement from unwrapping parenthesized conditions when the parentheses contain comments
  • add a regression example for the inline-comment case from the issue
  • add the required changelog entry

Why

swiftlint --fix was deleting inline comments in cases like if (abc == 1/* ... */) {}. This change takes the conservative path and skips those corrections instead of applying a destructive rewrite.

Testing

  • swift test --filter ControlStatementRuleGeneratedTests
  • ./.build/debug/swiftlint lint Source/SwiftLintBuiltInRules/Rules/Style/ControlStatementRule.swift CHANGELOG.md --strict
  • ./.build/debug/swiftlint lint --fix --only-rule control_statement /tmp/control_statement_comment.swift

Closes #6207

@SwiftLintBot
Copy link

20 Messages
📖 Building this branch resulted in a binary size of 27341.62 KiB vs 27357.74 KiB when built on main (-1% smaller).
📖 Linting Aerial with this PR took 0.22 s vs 0.2 s on main (9% slower).
📖 Linting Alamofire with this PR took 0.22 s vs 0.22 s on main (0% slower).
📖 Linting Brave with this PR took 0.82 s vs 0.84 s on main (2% faster).
📖 Linting DuckDuckGo with this PR took 3.34 s vs 3.36 s on main (0% faster).
📖 Linting Firefox with this PR took 1.53 s vs 1.54 s on main (0% faster).
📖 Linting Kickstarter with this PR took 0.97 s vs 0.96 s on main (1% slower).
📖 Linting Moya with this PR took 0.13 s vs 0.15 s on main (13% faster).
📖 Linting NetNewsWire with this PR took 0.35 s vs 0.37 s on main (5% faster).
📖 Linting Nimble with this PR took 0.18 s vs 0.16 s on main (12% slower).
📖 Linting PocketCasts with this PR took 0.91 s vs 0.93 s on main (2% faster).
📖 Linting Quick with this PR took 0.16 s vs 0.16 s on main (0% slower).
📖 Linting Realm with this PR took 0.43 s vs 0.42 s on main (2% slower).
📖 Linting Sourcery with this PR took 0.3 s vs 0.31 s on main (3% faster).
📖 Linting Swift with this PR took 0.52 s vs 0.49 s on main (6% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 3.86 s vs 3.84 s on main (0% slower).
📖 Linting VLC with this PR took 0.28 s vs 0.27 s on main (3% slower).
📖 Linting Wire with this PR took 2.01 s vs 1.97 s on main (2% slower).
📖 Linting WordPress with this PR took 1.36 s vs 1.33 s on main (2% slower).
📖 This PR fixed a violation in Swift: /stdlib/public/core/StringUTF16View.swift:577:7: Warning: if, for, guard, switch, while, and catch statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses (control_statement)

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.

control_statement kills inline comments

2 participants