mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
+4
-1
@@ -10,7 +10,10 @@
|
||||
|
||||
##### Bug Fixes
|
||||
|
||||
* None.
|
||||
* Fix a few edge cases where malformed `MARK:` comments wouldn't trigger a
|
||||
violation.
|
||||
[JP Simard](https://github.com/jpsim)
|
||||
[#805](https://github.com/realm/SwiftLint/issues/805)
|
||||
|
||||
## 0.13.0: MakeYourClothesCleanAgain
|
||||
|
||||
|
||||
@@ -19,22 +19,35 @@ public struct MarkRule: ConfigurationProviderRule {
|
||||
name: "Mark",
|
||||
description: "MARK comment should be in valid format.",
|
||||
nonTriggeringExamples: [
|
||||
"// MARK: good\n",
|
||||
"// MARK: - good\n",
|
||||
"// MARK: -\n"
|
||||
"// MARK: good",
|
||||
"// MARK: - good",
|
||||
"// MARK: -"
|
||||
],
|
||||
triggeringExamples: [
|
||||
"//MARK: bad",
|
||||
"// MARK:bad",
|
||||
"//MARK:bad",
|
||||
"// MARK: bad",
|
||||
"// MARK: bad",
|
||||
"// MARK: -bad",
|
||||
"// MARK:- bad",
|
||||
"// MARK:-bad",
|
||||
"//MARK:-bad"
|
||||
"//MARK: - bad",
|
||||
"//MARK:- bad",
|
||||
"//MARK: -bad",
|
||||
"//MARK:-bad",
|
||||
]
|
||||
)
|
||||
|
||||
public func validateFile(file: File) -> [StyleViolation] {
|
||||
let options = ["MARK:[^ ]", "[^ ]MARK: [^-]", "\\sMARK:[^ ]", "MARK:[ ][-][^\\s ]"]
|
||||
let pattern = "(" + options.joinWithSeparator("|") + ")"
|
||||
let nonSpace = "[^ ]"
|
||||
let twoOrMoreSpace = " {2,}"
|
||||
let nonSpaceOrTwoOrMoreSpace = "(\(nonSpace)|\(twoOrMoreSpace))"
|
||||
let mark = "MARK:"
|
||||
let badSpaceStart = "(\(nonSpaceOrTwoOrMoreSpace)?\(mark)\(nonSpaceOrTwoOrMoreSpace))"
|
||||
let badSpaceEnd = "(\(nonSpaceOrTwoOrMoreSpace)\(mark)\(nonSpaceOrTwoOrMoreSpace)?)"
|
||||
let badSpaceAfterHyphen = "(\(mark) -([^ \\n]|\(twoOrMoreSpace)))"
|
||||
let pattern = [badSpaceStart, badSpaceEnd, badSpaceAfterHyphen].joinWithSeparator("|")
|
||||
|
||||
return file.matchPattern(pattern, withSyntaxKinds: [.Comment]).flatMap { range in
|
||||
return StyleViolation(ruleDescription: self.dynamicType.description,
|
||||
|
||||
Reference in New Issue
Block a user