Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
[SimplyDanny](https://github.com/SimplyDanny)
[#6466](https://github.com/realm/SwiftLint/issues/6466)

* Measure alignment columns in `vertical_parameter_alignment_on_call` using
character positions instead of raw UTF-8 columns, avoiding false positives
when a preceding line contains multi-byte characters.
[theamodhshetty](https://github.com/theamodhshetty)
[#6467](https://github.com/realm/SwiftLint/issues/6467)

## 0.63.2: High-Speed Extraction

### Breaking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ struct VerticalParameterAlignmentOnCallRule: Rule {
// completion
}
"""),
Example("""
func test() {
СreateAdUpdateShopHelper.updateShopModels(categoryModels: &categoryModels,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we do the following, the test case would fail (with adapted parameter indentation):

Suggested change
СreateAdUpdateShopHelper.updateShopModels(categoryModels: &categoryModels,
СreateAd😵‍💫UpdateShopHelper.updateShopModels(categoryModels: &categoryModels,

There might exist code you can reuse. I remember that we have done something similar in other rules already, but can't remember where exactly.

contactModels: &contactModels,
country: response.country!,
contact: response.contact,
shop: response.shop)
}
"""),
],
triggeringExamples: [
Example("""
Expand Down Expand Up @@ -132,7 +141,7 @@ private extension VerticalParameterAlignmentOnCallRule {
return
}

var firstArgumentLocation = locationConverter.location(for: firstArg.positionAfterSkippingLeadingTrivia)
var firstArgumentLocation = characterLocation(for: firstArg.positionAfterSkippingLeadingTrivia)

var visitedLines = Set<Int>()
var previousArgumentWasMultiline = false
Expand All @@ -144,7 +153,7 @@ private extension VerticalParameterAlignmentOnCallRule {
}

let position = argument.positionAfterSkippingLeadingTrivia
let location = locationConverter.location(for: position)
let location = characterLocation(for: position)
guard location.line > firstArgumentLocation.line else {
return nil
}
Expand Down Expand Up @@ -174,5 +183,26 @@ private extension VerticalParameterAlignmentOnCallRule {

return endPosition.line > startPosition.line
}

private func characterLocation(for position: AbsolutePosition) -> SourceLocation {
let location = locationConverter.location(for: position)

let characterColumn: Int
let graphemeClusters = String(
locationConverter.sourceLines[location.line - 1].utf8.prefix(location.column - 1)
)
if let graphemeClusters {
characterColumn = graphemeClusters.count + 1
} else {
characterColumn = location.column
}

return SourceLocation(
line: location.line,
column: characterColumn,
offset: location.offset,
file: location.file
)
}
}
}