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

Fix crash when disable command is preceded by unicode character #5976

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SimplyDanny
Copy link
Collaborator

Fixes #5945.

@SwiftLintBot
Copy link

SwiftLintBot commented Jan 21, 2025

1 Warning
⚠️ This PR may need tests.
18 Messages
📖 Building this branch resulted in a binary size of 29489.02 KiB vs 29488.71 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.89 s vs 0.18 s on main (394% slower).
📖 Linting Alamofire with this PR took 0.15 s vs 0.15 s on main (0% slower).
📖 Linting Brave with this PR took 0.61 s vs 0.59 s on main (3% slower).
📖 Linting DuckDuckGo with this PR took 0.45 s vs 0.47 s on main (4% faster).
📖 Linting Firefox with this PR took 0.86 s vs 0.87 s on main (1% faster).
📖 Linting Kickstarter with this PR took 0.56 s vs 0.57 s on main (1% faster).
📖 Linting Moya with this PR took 0.13 s vs 0.13 s on main (0% slower).
📖 Linting NetNewsWire with this PR took 0.23 s vs 0.24 s on main (4% faster).
📖 Linting Nimble with this PR took 0.13 s vs 0.13 s on main (0% slower).
📖 Linting PocketCasts with this PR took 0.57 s vs 0.57 s on main (0% slower).
📖 Linting Quick with this PR took 0.12 s vs 0.12 s on main (0% slower).
📖 Linting Realm with this PR took 0.36 s vs 0.37 s on main (2% faster).
📖 Linting Sourcery with this PR took 0.27 s vs 0.25 s on main (8% slower).
📖 Linting Swift with this PR took 0.33 s vs 0.33 s on main (0% slower).
📖 Linting VLC with this PR took 0.17 s vs 0.17 s on main (0% slower).
📖 Linting Wire with this PR took 1.47 s vs 1.5 s on main (2% faster).
📖 Linting WordPress with this PR took 0.83 s vs 0.88 s on main (5% faster).

Generated by 🚫 Danger

@SimplyDanny SimplyDanny force-pushed the unicode-before-command branch from 5905446 to db786b3 Compare January 22, 2025 20:13
@@ -60,35 +62,54 @@ struct InvalidSwiftLintCommandRule: Rule, SourceKitFreeRule {

private func styleViolation(for command: Command, in file: SwiftLintFile, reason: String) -> StyleViolation {
let character = command.startingCharacterPosition(in: file)
let characterOffset = character.flatMap {
Copy link
Collaborator

Choose a reason for hiding this comment

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

So I think we could make the characterOffset retrieval a function on the Command extension, so this reads more nicely here, but having to do all of these line calculations feels a bit off in general.

The reason we have to do this calculations is because Command's character property records the character beyond the end of the command. If that instead recorded the start of the command, which is where this rule places the violation, then we could ditch all of this code.

I think that might be possible, but something we could look at separately.

@@ -18,6 +18,9 @@

* Fix issue referencing the Tests package from another Bazel workspace.
[jszumski](https://github.com/jszumski)
* Fix crash when a disable command is preceded by a unicode character.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe a blank line here?

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.

Crash with swiftlint directive after emoji with skin tone
3 participants