-
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
Out of range exception in AttributesRule #1105
Labels
bug
Unexpected and reproducible misbehavior.
Comments
Reduced crasher to |
I have to leave, but here's the fix: diff --git a/Source/SwiftLintFramework/Rules/AttributesRule.swift b/Source/SwiftLintFramework/Rules/AttributesRule.swift
index 598936b..57b1f74 100644
--- a/Source/SwiftLintFramework/Rules/AttributesRule.swift
+++ b/Source/SwiftLintFramework/Rules/AttributesRule.swift
@@ -258,15 +258,14 @@ public struct AttributesRule: ASTRule, OptInRule, ConfigurationProviderRule {
let restOfLineOffset = attributeRange.location + attributeRange.length
let restOfLineLength = line.byteRange.location + line.byteRange.length - restOfLineOffset
- let range = NSRange(location: 0, length: restOfLineLength)
let regex = AttributesRule.regularExpression
let contents = file.contents.bridge()
// check if after the token is a `(` with only spaces allowed between the token and `(`
guard let restOfLine = contents.substringWithByteRange(start: restOfLineOffset,
length: restOfLineLength),
+ case let range = NSRange(location: 0, length: restOfLine.bridge().length),
regex.firstMatch(in: restOfLine, options: [], range: range) != nil else {
-
return false
}
diff --git a/Source/SwiftLintFramework/Rules/AttributesRulesExamples.swift b/Source/SwiftLintFramework/Rules/AttributesRulesExamples.swift
index 9fcb07b..2fba66a 100644
--- a/Source/SwiftLintFramework/Rules/AttributesRulesExamples.swift
+++ b/Source/SwiftLintFramework/Rules/AttributesRulesExamples.swift
@@ -35,6 +35,7 @@ internal struct AttributesRuleExamples {
"@objc(ABCThing)\n @available(iOS 9.0, *)\n class Thing",
"class Foo: NSObject {\n override var description: String { return \"\" }\n}",
"class Foo: NSObject {\n\n override func setUp() {}\n}",
+ "@objc\nclass ⽺ {}\n",
// attribute with allowed empty new line above
"extension Property {\n\n @available(*, unavailable, renamed: \"isOptional\")\n" + |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When running on
test/Interpreter/SDK/objc_mangling.swift
from Swift's source.The text was updated successfully, but these errors were encountered: