Skip to content

Fix vertical_parameter_alignment false positive with multi-byte function names#6747

Merged
SimplyDanny merged 2 commits into
realm:mainfrom
systemblueio:fix/5037-vertical-parameter-alignment-multibyte
Jun 6, 2026
Merged

Fix vertical_parameter_alignment false positive with multi-byte function names#6747
SimplyDanny merged 2 commits into
realm:mainfrom
systemblueio:fix/5037-vertical-parameter-alignment-multibyte

Conversation

@systemblueio
Copy link
Copy Markdown
Contributor

Fixes #5037.

vertical_parameter_alignment compared parameter columns by UTF-8 byte offset, so a function name with multi-byte characters (e.g. a non-ASCII letter) shifted the byte column of visually aligned continuation parameters and produced a false violation.

This converts each parameter column to a grapheme-cluster column before comparing, the same approach collection_alignment already uses. A non-triggering regression example covering the reported signature is added.

Verified with swift test --filter VerticalParameterAlignment and the broader rule suite (--filter RulesTests); linting the issue's snippet now reports no violation while genuine misalignment is still flagged.

🤖 Generated with Claude Code

…e names

`vertical_parameter_alignment` compared parameter alignment using UTF-8 byte
columns. When characters before the parameters span more than one byte (such as
a function name containing non-ASCII letters), the byte column of a visually
aligned continuation parameter no longer matched the first parameter's byte
column, producing a false violation.

Convert each parameter column to a grapheme-cluster column before comparing,
matching the approach already used by `collection_alignment`. Add a
non-triggering regression example covering the reported signature.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@SwiftLintBot
Copy link
Copy Markdown

SwiftLintBot commented Jun 5, 2026

19 Messages
📖 Building this branch resulted in the same binary size as when built on main.
📖 Linting Aerial with this PR took 0.73 s vs 0.75 s on main (2% faster).
📖 Linting Alamofire with this PR took 1.05 s vs 1.03 s on main (1% slower).
📖 Linting Brave with this PR took 7.08 s vs 7.11 s on main (0% faster).
📖 Linting DuckDuckGo with this PR took 29.36 s vs 29.25 s on main (0% slower).
📖 Linting Firefox with this PR took 12.34 s vs 12.25 s on main (0% slower).
📖 Linting Kickstarter with this PR took 8.38 s vs 8.27 s on main (1% slower).
📖 Linting Moya with this PR took 0.43 s vs 0.43 s on main (0% slower).
📖 Linting NetNewsWire with this PR took 2.7 s vs 2.69 s on main (0% slower).
📖 Linting Nimble with this PR took 0.66 s vs 0.65 s on main (1% slower).
📖 Linting PocketCasts with this PR took 8.28 s vs 8.03 s on main (3% slower).
📖 Linting Quick with this PR took 0.39 s vs 0.42 s on main (7% faster).
📖 Linting Realm with this PR took 2.92 s vs 2.87 s on main (1% slower).
📖 Linting Sourcery with this PR took 1.83 s vs 1.82 s on main (0% slower).
📖 Linting Swift with this PR took 4.78 s vs 4.59 s on main (4% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 0.16 s vs 0.16 s on main (0% slower).
📖 Linting VLC with this PR took 1.18 s vs 1.18 s on main (0% slower).
📖 Linting Wire with this PR took 18.25 s vs 18.31 s on main (0% faster).
📖 Linting WordPress with this PR took 12.48 s vs 12.47 s on main (0% slower).

Generated by 🚫 Danger

@kapitoshka438
Copy link
Copy Markdown
Contributor

Aren't multi-byte names evil? Wouldn't it be better to avoid such names, either by the current rule or some other rule, rather than hiding the problem? Is there a more useful example of a name, rather than one that only causes confusion between variations of the "c" character?

@SimplyDanny SimplyDanny added this to the 0.64.0 milestone Jun 5, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@systemblueio
Copy link
Copy Markdown
Contributor Author

Fair point on the example, so I swapped the homoglyph name for a realistic accented one (résuméBuilder); on the wider question, non-ASCII identifiers are legal Swift and common in non-English codebases, so this rule should measure alignment correctly regardless, and discouraging such names feels like identifier_name's territory rather than an alignment rule's.

Copy link
Copy Markdown
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good to me.

@SimplyDanny SimplyDanny enabled auto-merge (squash) June 6, 2026 08:39
@SimplyDanny
Copy link
Copy Markdown
Collaborator

SimplyDanny commented Jun 6, 2026

Aren't multi-byte names evil? Wouldn't it be better to avoid such names, either by the current rule or some other rule, rather than hiding the problem? Is there a more useful example of a name, rather than one that only causes confusion between variations of the "c" character?

I think that all rules should generally be able to deal with multi-byte characters in code, especially in Swift code where this totally allowed and sometimes common. They should be able to handle the difference between byte-count and visible character length.

Unintentionally confusing characters is a different topic and could be addressed by a dedicated rule. Sounds reasonable to me to lint on non-ASCII characters that look like ones (for example). Feel free to open a "Rule Request" in a separate issue, @kapitoshka438.

@SimplyDanny SimplyDanny merged commit 0f2b4f6 into realm:main Jun 6, 2026
26 checks passed
@systemblueio
Copy link
Copy Markdown
Contributor Author

systemblueio commented Jun 6, 2026

Thanks for the quick review and merge, glad it landed, and we'll be around to help with more fixes whenever they come up.

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.

False positive: vertical_parameter_alignment with specific function name

4 participants