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

False positive for the collection_alignment rule when "…" is used #4837

Closed
2 tasks done
BobbyRohweder opened this issue Mar 25, 2023 · 3 comments · Fixed by #5173
Closed
2 tasks done

False positive for the collection_alignment rule when "…" is used #4837

BobbyRohweder opened this issue Mar 25, 2023 · 3 comments · Fixed by #5173
Labels
bug Unexpected and reproducible misbehavior.

Comments

@BobbyRohweder
Copy link

New Issue Checklist

Describe the bug

A false positive warning occurs for the collection_alignment Rule when using "…" in the first line.
Adding 2 more spaces to the second line will resolve the issue, and seems as if "…" is considered 3 characters.

Example:

NSAttributedString(string: "…", attributes: [.font: UIFont.systemFont(ofSize: 12, weight: .regular),
                                             .foregroundColor: UIColor(white: 0, alpha: 0.2)])

A clear and concise description of what the bug is.

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint

Error:

<failure message='All elements in a collection literal should be vertically aligned'>error:
Line:78 </failure>

Rules:

opt_in_rules:
    - collection_alignment

Environment

Swiftlint version: 0.50.3

@BobbyRohweder BobbyRohweder changed the title The collection_alignment Rule Fails When "…" is Used False positive for the collection_alignment rule when "…" is used Mar 25, 2023
@mildm8nnered
Copy link
Collaborator

The system does a lot of mapping between ellipsis and three dots. For example, on MacOS menu items defined with three dots, and those defined with the ellipsis will appear identical. This treatment can vary subtly between OS's - we had to update a unit test for Ventura on my product for a case where we were expecting to see three dots, but instead now got ellipsis, or possibly vice versa.

"Unicode recognizes a series of three period characters (U+002E) as compatibility equivalent (though not canonical) to the horizontal ellipsis character".

@mildm8nnered
Copy link
Collaborator

I think this could be tricky to fix in SwiftLint itself, because we're getting the locations via element.positionAfterSkippingLeadingTrivia, which is defined in SwiftSyntax, so that's where we're getting the wrong positions from.

In fact, print("length = \("…".utf8.count)") will produce 3, so the problem is even deeper than that.

The best workaround for you is probably just to use three dots instead - in almost all contexts, where these should be ellipsis, the OS will automatically render them correctly for you.

@SimplyDanny
Copy link
Collaborator

Thank you for the insights, @mildm8nnered! However, this issue is not specific to the ellipsis. We can observe the same for emoji. So I think this is a general issue with how SwiftLint interprets text.

It's not always right to go down to the encoding level. Here, it's about what's visible to the user. In the case of the ellipsis, it's 1 character ("…".count). In case of 🤷‍♂️, it's also 1 character but "🤷‍♂️".utf8.count == 13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
3 participants