Repository navigation
Fix literal_expression_end_indentation correction deleting code - #6769
Merged
SimplyDanny merged 1 commit intoJun 14, 2026
Merged
SimplyDanny merged 1 commit into
SimplyDanny merged 1 commit into
Conversation
The corrector assumed everything before the closing bracket on its line was indentation and replaced that whole range with the expected indentation. When a multiline last element ends on the same line as the bracket (e.g. `...))]`), the range contains source code, which got deleted and produced non-compiling output. Only perform the in-place replacement when the range is all whitespace; otherwise insert a newline plus the expected indentation right before the bracket, moving just the bracket to its own line. Fixes the corrector half of realm#2823.
2 tasks done
Generated by 🚫 Danger |
SimplyDanny
approved these changes
Jun 14, 2026
SimplyDanny
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @luancamara!
SimplyDanny
enabled auto-merge (squash)
June 14, 2026 20:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2823.
(The fix targets the rule's corrector; detection behavior is unchanged.)
Bug
When the closing bracket of a multiline literal shares a line with the end of a multiline last element, the
literal_expression_end_indentationcorrector deletes source code and produces non-compiling output.Minimal reproduction (SwiftLint 0.63.3, config
only_rules: [literal_expression_end_indentation]):swiftlint --fixrewrites the last line to], deleting2). Real-world case we hit:font: .caption(.regular))],became],— an entire argument silently dropped. We only caught it because the parentheses became unbalanced; a balanced collapse would have been a silent behavior change.Root cause
correct(contents:expected:actual:)assumes everything before the bracket on its line is indentation and replaces that whole range with the expected indentation. The violation geometry (actualRangecovers the full line prefix before]) admits ranges containing code when the last element is multiline.Fix
Only perform the in-place replacement when the range is all whitespace; otherwise insert a newline plus the expected indentation right before the bracket, moving just the bracket to its own line. Detection behavior is unchanged; the rule's built-in re-correct pass converges (verified idempotent).
Testing
swift test --filter LiteralExpressionEndIndentationpasses.--fixrun makes no changes.