-
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
mark breaks when fixing and MARK:
is found inside a comment block
#3841
Comments
An example from real life is a simple commented out block of code that contained MARKS: import Foundation
/*
let release = "release/1.3.0"
let base = "https://raw.githubusercontent.com/ehn-dcc-development/ehn-dcc-schema/\(release)/valuesets"
guard let baseURL = URL(string: base) else {
fatalError("Couldn't convert base baseUrl to a URL")
}
let unknownCase = "\tcase unknown = \"unknown\""
let unknownDisplay = "\t\tcase .unknown: return \"unknown\""
let displaySequence = [
"\tpublic var display: String {",
"\t\tswitch self {",
unknownDisplay
]
let closingSequence = [
"\t\t}",
"\t}",
"}",
""
]
// MARK: - ValueConverter
protocol ValueConverter {
var input: String { get }
var output: String { get }
func output(_ values: [String: EUValSetValue], to filename: String)
}
// MARK: - CountryCode
*/ |
A possible solution would be to change the patterns that are being searched for and not rely on the fact that a |
Duplicate of #1749? |
😱 yes, yes it is... 🙈 should I just close this issue (and possibly add the information to the other issue)? edit: actually, I'll fix it and create a PR 🙈 |
If your PR fixes the bug both issues will be closed anyway. Otherwise
would possibly be preferred. |
that was my reasoning as well, so I left it here, while mentioning both issues in the PR (with a "fixes" tag) 🙈 |
New Issue Checklist
Describe the bug
The mark rule breaks if
MARK:
is found anywhere inside a comment block.The issue lies in that the mark rule takes the location of the comment block as the location of the
MARK:
and changes the whole range to// MARK:
.Since the length of the ranges that are converted to
// MARK:
are wrong, this ultimately causes a crash (more info below)An example that shows this clearly (without a crash):
This will be converted into (notice the missing opening comment tag on line 0):
If multiple
MARK:
are found inside a comment block (example at end of description), the ranges found always start at/*
, while the lengths will be calculated to the colon for eachMARK:
. Too long ranges are then replaced and the resulting string can become too short, which results in anNSInvalidArgumentException - Range or index out of bounds
exception here.The individual ranges are calculated in violationRanges(in:matching:), where it's obvious that the location of the found comment token (
syntaxTokens[0].offset
) is used, and not the location for the actual MARK.This issue is specifically related to the
spaceStartPattern
, but other patterns make use of the same logic and might trigger the same issue.Complete output when running SwiftLint, including the stack trace and command used
Environment
SwiftLint version: 0.46.2
Installation method used: Homebrew and built from sources (for debugging)
No configuration file was used
Xcode 13.2.1 - Build version 13C100
Sample that breaks on
swiftlint --fix
:The text was updated successfully, but these errors were encountered: