Skip to content

Commit

Permalink
Merge pull request #128 from realm/jp-generalize-todo-rule
Browse files Browse the repository at this point in the history
Generalize TodoRule
  • Loading branch information
jpsim committed Sep 19, 2015
2 parents d2496d8 + 75f4122 commit f8e226d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions Source/SwiftLintFramework/Rules/TodoRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@

import SourceKittenFramework

extension SyntaxKind {
/// Returns if the syntax kind is comment-like.
public var isCommentLike: Bool {
return [Comment, CommentMark, CommentURL, DocComment, DocCommentField].contains(self)
}
}

public struct TodoRule: Rule {
public init() {}

public let identifier = "todo"

public func validateFile(file: File) -> [StyleViolation] {
return file.matchPattern("// (TODO|FIXME):", withSyntaxKinds: [.Comment]).map { range in
return file.matchPattern("\\b(TODO|FIXME)\\b").flatMap { range, syntaxKinds in
if syntaxKinds.filter({ !$0.isCommentLike }).count > 0 {
return nil
}
return StyleViolation(type: .TODO,
location: Location(file: file, offset: range.location),
severity: .Warning,
Expand All @@ -26,12 +36,18 @@ public struct TodoRule: Rule {
ruleName: "Todo Rule",
ruleDescription: "This rule checks whether you removed all TODOs and FIXMEs.",
nonTriggeringExamples: [
"let string = \"// TODO:\"\n",
"let string = \"// FIXME:\"\n"
"// notaTODO:\n",
"// notaFIXME:\n"
],
triggeringExamples: [
"// TODO:\n",
"// FIXME:\n"
"// FIXME:\n",
"// TODO(note)\n",
"// FIXME(note)\n",
"/* FIXME: */\n",
"/* TODO: */\n",
"/** FIXME: */\n",
"/** TODO: */\n"
]
)
}

0 comments on commit f8e226d

Please sign in to comment.