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 2 commits into
base: main
Choose a base branch
from

Conversation

SimplyDanny
Copy link
Collaborator

Fixes #5945.

@SwiftLintBot
Copy link

SwiftLintBot commented Jan 21, 2025

19 Warnings
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Sources/SourceList.swift:122:8: warning: Superfluous Disable Command Violation: SwiftLint rule 'for_where' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Firefox: /firefox-ios/Client/AdjustHelper.swift:1:4: warning: Superfluous Disable Command Violation: SwiftLint rule 'file_header' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Firefox: /firefox-ios/Client/AdjustTelemetryHelper.swift:1:4: warning: Superfluous Disable Command Violation: SwiftLint rule 'file_header' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Firefox: /firefox-ios/Client/Frontend/PasswordManagement/Cells/LoginDetailTableViewCell.swift:89:12: warning: Superfluous Disable Command Violation: SwiftLint rule 'unused_setter_value' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Firefox: /firefox-ios/Client/Frontend/Settings/Main/Account/SyncNowSetting.swift:155:12: warning: Superfluous Disable Command Violation: SwiftLint rule 'unused_setter_value' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Firefox: /firefox-ios/Client/TabManagement/Tab.swift:1179:8: warning: Superfluous Disable Command Violation: SwiftLint rule 'unneeded_override' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Firefox: /firefox-ios/Client/Telemetry/Wrapper/AdjustWrapper.swift:1:4: warning: Superfluous Disable Command Violation: SwiftLint rule 'file_header' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Firefox: /firefox-ios/firefox-ios-tests/Tests/ClientTests/Helpers/AdjustTelemetryHelperTests.swift:1:4: warning: Superfluous Disable Command Violation: SwiftLint rule 'file_header' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Kickstarter: /Library/Strings.swift:7:4: warning: Superfluous Disable Command Violation: 'valid_docs' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Kickstarter: /Library/Strings.swift:8:4: warning: Superfluous Disable Command Violation: 'valid_docs' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Kickstarter: /Library/ViewModels/PledgePaymentMethodsViewModelTests.swift:45:8: warning: Superfluous Disable Command Violation: SwiftLint rule 'line_length' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Realm: /RealmSwift/Tests/PrimitiveMapTests.swift:23:4: warning: Superfluous Disable Command Violation: SwiftLint rule 'cyclomatic_complexity' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Sourcery: /Templates/Tests/Generated/AutoEquatable.generated.swift:3:4: warning: Superfluous Disable Command Violation: SwiftLint rule 'file_length' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Wire: /wire-ios-data-model/Tests/Source/Model/User/ZMUserTests+Swift.swift:880:12: warning: Superfluous Disable Command Violation: 'todo_requires_jira_link' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Wire: /wire-ios-sync-engine/Source/SessionManager/SessionManager.swift:660:16: warning: Superfluous Disable Command Violation: 'todo_requires_jira_link' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Wire: /wire-ios-sync-engine/Source/UserSession/UserSession.swift:140:8: warning: Superfluous Disable Command Violation: 'todo_requires_jira_link' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Wire: /wire-ios-sync-engine/Tests/Source/SessionManager/SessionManagerTests+MultiUserSession.swift:380:12: warning: Superfluous Disable Command Violation: 'todo_requires_jira_link' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in Wire: /wire-ios/Wire-iOS/Sources/UserInterface/ConversationList/ListContent/ConversationListContentController/ViewModel/ConversationListViewModel.swift:477:16: warning: Superfluous Disable Command Violation: 'todo_requires_jira_link' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
⚠️ This PR introduced a violation in WordPress: /WordPressAuthenticator/Sources/Unified Auth/View Related/Password/PasswordViewController.swift:142:20: warning: Superfluous Disable Command Violation: 'localization_comment' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
48 Messages
📖 Building this branch resulted in a binary size of 29489.05 KiB vs 29488.84 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.96 s vs 0.94 s on main (2% slower).
📖 Linting Alamofire with this PR took 1.27 s vs 1.29 s on main (1% faster).
📖 Linting Brave with this PR took 8.64 s vs 8.66 s on main (0% faster).
📖 Linting DuckDuckGo with this PR took 5.6 s vs 5.59 s on main (0% slower).
📖 Linting Firefox with this PR took 11.63 s vs 11.67 s on main (0% faster).
📖 Linting Kickstarter with this PR took 10.54 s vs 10.53 s on main (0% slower).
📖 Linting Moya with this PR took 0.53 s vs 0.54 s on main (1% faster).
📖 Linting NetNewsWire with this PR took 2.93 s vs 2.94 s on main (0% faster).
📖 Linting Nimble with this PR took 0.8 s vs 0.79 s on main (1% slower).
📖 Linting PocketCasts with this PR took 8.83 s vs 8.84 s on main (0% faster).
📖 Linting Quick with this PR took 0.45 s vs 0.45 s on main (0% slower).
📖 Linting Realm with this PR took 4.53 s vs 4.52 s on main (0% slower).
📖 Linting Sourcery with this PR took 2.34 s vs 2.34 s on main (0% slower).
📖 Linting Swift with this PR took 4.62 s vs 4.6 s on main (0% slower).
📖 Linting VLC with this PR took 1.25 s vs 1.27 s on main (1% faster).
📖 Linting Wire with this PR took 18.62 s vs 18.63 s on main (0% faster).
📖 Linting WordPress with this PR took 11.6 s vs 11.56 s on main (0% slower).
📖 This PR fixed a violation in Aerial: /Aerial/Source/Models/Sources/SourceList.swift:122:35: warning: Superfluous Disable Command Violation: SwiftLint rule 'for_where' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Firefox: /firefox-ios/Client/AdjustHelper.swift:1:49: warning: Superfluous Disable Command Violation: SwiftLint rule 'file_header' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Firefox: /firefox-ios/Client/AdjustTelemetryHelper.swift:1:49: warning: Superfluous Disable Command Violation: SwiftLint rule 'file_header' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Firefox: /firefox-ios/Client/Frontend/PasswordManagement/Cells/LoginDetailTableViewCell.swift:89:49: warning: Superfluous Disable Command Violation: SwiftLint rule 'unused_setter_value' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Firefox: /firefox-ios/Client/Frontend/Settings/Main/Account/SyncNowSetting.swift:155:49: warning: Superfluous Disable Command Violation: SwiftLint rule 'unused_setter_value' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Firefox: /firefox-ios/Client/TabManagement/Tab.swift:1179:43: warning: Superfluous Disable Command Violation: SwiftLint rule 'unneeded_override' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Firefox: /firefox-ios/Client/Telemetry/Wrapper/AdjustWrapper.swift:1:49: warning: Superfluous Disable Command Violation: SwiftLint rule 'file_header' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Firefox: /firefox-ios/firefox-ios-tests/Tests/ClientTests/Helpers/AdjustTelemetryHelperTests.swift:1:49: warning: Superfluous Disable Command Violation: SwiftLint rule 'file_header' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Kickstarter: /Library/Strings.swift:7:32: warning: Superfluous Disable Command Violation: 'valid_docs' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Kickstarter: /Library/Strings.swift:8:33: warning: Superfluous Disable Command Violation: 'valid_docs' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Kickstarter: /Library/ViewModels/PledgePaymentMethodsViewModelTests.swift:45:37: warning: Superfluous Disable Command Violation: SwiftLint rule 'line_length' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
📖 This PR fixed a violation in NetNewsWire: /Widget/Resources/Localized.swift:1:22: warning: Blanket Disable Command Violation: Use 'next', 'this' or 'previous' instead to disable the 'all' rule once, or re-enable it as soon as possible` (blanket_disable_command)
📖 This PR fixed a violation in PocketCasts: /Modules/Server/Sources/PocketCastsServer/Private/Protobuffer/api.pb.swift:3:22: warning: Blanket Disable Command Violation: Use 'next', 'this' or 'previous' instead to disable the 'all' rule once, or re-enable it as soon as possible` (blanket_disable_command)
📖 This PR fixed a violation in PocketCasts: /Modules/Server/Sources/PocketCastsServer/Private/Protobuffer/files.pb.swift:3:22: warning: Blanket Disable Command Violation: Use 'next', 'this' or 'previous' instead to disable the 'all' rule once, or re-enable it as soon as possible` (blanket_disable_command)
📖 This PR fixed a violation in PocketCasts: /podcasts/Strings+Generated.swift:1:22: warning: Blanket Disable Command Violation: Use 'next', 'this' or 'previous' instead to disable the 'all' rule once, or re-enable it as soon as possible` (blanket_disable_command)
📖 This PR fixed a violation in Realm: /RealmSwift/Tests/PrimitiveMapTests.swift:23:43: warning: Superfluous Disable Command Violation: SwiftLint rule 'cyclomatic_complexity' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Sourcery: /SourceryRuntime/Sources/Generated/AutoHashable.generated.swift:3:22: warning: Blanket Disable Command Violation: Use 'next', 'this' or 'previous' instead to disable the 'all' rule once, or re-enable it as soon as possible` (blanket_disable_command)
📖 This PR fixed a violation in Sourcery: /Templates/Tests/Generated/AutoEquatable.generated.swift:3:33: warning: Superfluous Disable Command Violation: SwiftLint rule 'file_length' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Sourcery: /Templates/Tests/Generated/AutoHashable.generated.swift:3:22: warning: Blanket Disable Command Violation: Use 'next', 'this' or 'previous' instead to disable the 'all' rule once, or re-enable it as soon as possible` (blanket_disable_command)
📖 This PR fixed a violation in Wire: /wire-ios-data-model/Tests/Source/Model/User/ZMUserTests+Swift.swift:880:53: warning: Superfluous Disable Command Violation: 'todo_requires_jira_link' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Wire: /wire-ios-protos/Protos/messages.pb.swift:21:22: warning: Blanket Disable Command Violation: Use 'next', 'this' or 'previous' instead to disable the 'all' rule once, or re-enable it as soon as possible` (blanket_disable_command)
📖 This PR fixed a violation in Wire: /wire-ios-protos/Protos/mls.pb.swift:21:22: warning: Blanket Disable Command Violation: Use 'next', 'this' or 'previous' instead to disable the 'all' rule once, or re-enable it as soon as possible` (blanket_disable_command)
📖 This PR fixed a violation in Wire: /wire-ios-protos/Protos/otr.pb.swift:21:22: warning: Blanket Disable Command Violation: Use 'next', 'this' or 'previous' instead to disable the 'all' rule once, or re-enable it as soon as possible` (blanket_disable_command)
📖 This PR fixed a violation in Wire: /wire-ios-sync-engine/Source/SessionManager/SessionManager.swift:660:57: warning: Superfluous Disable Command Violation: 'todo_requires_jira_link' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Wire: /wire-ios-sync-engine/Source/UserSession/UserSession.swift:140:49: warning: Superfluous Disable Command Violation: 'todo_requires_jira_link' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Wire: /wire-ios-sync-engine/Tests/Source/SessionManager/SessionManagerTests+MultiUserSession.swift:380:53: warning: Superfluous Disable Command Violation: 'todo_requires_jira_link' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
📖 This PR fixed a violation in Wire: /wire-ios/Wire-iOS Share Extension/Generated/Strings+Generated.swift:1:22: warning: Blanket Disable Command Violation: Use 'next', 'this' or 'previous' instead to disable the 'all' rule once, or re-enable it as soon as possible` (blanket_disable_command)
📖 This PR fixed a violation in Wire: /wire-ios/Wire-iOS/Generated/Strings+Generated.swift:1:22: warning: Blanket Disable Command Violation: Use 'next', 'this' or 'previous' instead to disable the 'all' rule once, or re-enable it as soon as possible` (blanket_disable_command)
📖 This PR fixed a violation in Wire: /wire-ios/Wire-iOS/Sources/UserInterface/ConversationList/ListContent/ConversationListContentController/ViewModel/ConversationListViewModel.swift:477:57: warning: Superfluous Disable Command Violation: 'todo_requires_jira_link' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)
📖 This PR fixed a violation in WordPress: /WordPressAuthenticator/Sources/Unified Auth/View Related/Password/PasswordViewController.swift:142:58: warning: Superfluous Disable Command Violation: 'localization_comment' is not a valid SwiftLint rule; remove it from the disable command (superfluous_disable_command)

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.

Copy link
Collaborator

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 ...

Copy link
Collaborator Author

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.

@SimplyDanny SimplyDanny force-pushed the unicode-before-command branch from db786b3 to f486bb3 Compare January 26, 2025 15:49
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