Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update redundantClosure rule to preserve closure where if/switch expression would not be allowed #1553

Merged

Conversation

calda
Copy link
Collaborator

@calda calda commented Oct 15, 2023

This PR updates the redundantClosure rule to preserve closures with if/switch expressions if the closure is in a position where an if/switch expression would not be allowed. In Swift 5.9 if/switch expressions are only allowed as either return values, or as the result of an assignment.

This PR also fixes miscellaneous issues where redundantClosure didn't properly handle some combinations of explicit return, try/await, and if/switch expressions.

Fixes #1547 and #1548.

@@ -1822,6 +1822,11 @@ class ParsingHelpersTests: XCTestCase {
XCTAssert(isSingleExpression(#"#selector(Foo.bar)"#))
XCTAssert(isSingleExpression(#"#macro()"#))
XCTAssert(isSingleExpression(#"#outerMacro(12, #innerMacro(34), "some text")"#))
XCTAssert(isSingleExpression(#"try { try printThrows(foo) }()"#))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This previously failed to parse as a single expression

@codecov
Copy link

codecov bot commented Oct 15, 2023

Codecov Report

Merging #1553 (3f34cf8) into develop (e3ec9af) will increase coverage by 0.02%.
The diff coverage is 97.80%.

@@             Coverage Diff             @@
##           develop    #1553      +/-   ##
===========================================
+ Coverage    94.96%   94.98%   +0.02%     
===========================================
  Files           20       20              
  Lines        21670    21738      +68     
===========================================
+ Hits         20578    20648      +70     
+ Misses        1092     1090       -2     
Files Coverage Δ
Sources/ParsingHelpers.swift 96.60% <100.00%> (-0.01%) ⬇️
Sources/FormattingHelpers.swift 97.68% <97.22%> (+0.01%) ⬆️
Sources/Rules.swift 98.53% <98.14%> (-0.01%) ⬇️

... and 1 file with indirect coverage changes

@nicklockwood nicklockwood merged commit e9a9bc7 into nicklockwood:develop Oct 16, 2023
7 checks passed
@nicklockwood
Copy link
Owner

Thanks so much Cal ❤️

@calda
Copy link
Collaborator Author

calda commented Oct 16, 2023

Happy to heelllppp

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.

2 participants