From 04a1c5e2dfa38931c35de1c53df896a3ec97ce64 Mon Sep 17 00:00:00 2001 From: Edwin Vermeer Date: Wed, 3 Jun 2015 15:04:26 +0200 Subject: [PATCH] Option do ignore one or all rules for a file by adding a comment With this change you can disable all rules for a file by adding the following line to your swift file: // SwiftLint ignore all or you can disable a specific rule by adding something like: // SwiftLint ignore variable_name Where variable_name is the identifier of the rule --- Source/SwiftLintFramework/Linter.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/SwiftLintFramework/Linter.swift b/Source/SwiftLintFramework/Linter.swift index 9641a3bdeb..f6a22011dc 100644 --- a/Source/SwiftLintFramework/Linter.swift +++ b/Source/SwiftLintFramework/Linter.swift @@ -31,7 +31,14 @@ public struct Linter { ] public var styleViolations: [StyleViolation] { - return rules.flatMap { $0.validateFile(file) } + return rules.flatMap { + if !(file.contents as NSString).containsString("// SwiftLint ignore \($0.identifier)") + && !(file.contents as NSString).containsString("// SwiftLint ignore all") { + return $0.validateFile(file) + } else { + return [] + } + } } public var ruleExamples: [RuleExample] {