-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
base: main
Are you sure you want to change the base?
Conversation
5905446
to
db786b3
Compare
@@ -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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe just record the range of the Command at least both the start and end somehow ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to record the beginning of the command instead. This indeed simplifies the code in the rule. However, at some point we need to perform the byte and position calculations, unfortunately, which is CommandVisitor
now.
Going from an absolute byte position to a character doesn't seem to be obvious. That's what characterPosition(of:)
is doing. In case you have a better idea, I'm open for it.
db786b3
to
f486bb3
Compare
Fixes #5945.