         }
     }
 
-    private func importGroups(in file: File) -> [[Line]] {
-        let importRanges = file.match(pattern: "import\\s+\\w+", with: [.keyword, .identifier])
-        let enabledImportRanges = file.ruleEnabled(violatingRanges: importRanges, for: self)
+    private func importGroups(in file: File, filterEnabled: Bool) -> [[Line]] {
+        var importRanges = file.match(pattern: "import\\s+\\w+", with: [.keyword, .identifier])
+        if filterEnabled {
+            importRanges = file.ruleEnabled(violatingRanges: importRanges, for: self)
+        }
 
         let contents = file.contents.bridge()
         let lines = contents.lines()
-        let importLines: [Line] = enabledImportRanges.flatMap { range in
+        let importLines: [Line] = importRanges.flatMap { range in
             guard let line = contents.lineAndCharacter(forCharacterOffset: range.location)?.line
                 else { return nil }
             return lines[line - 1]

import Foundation
import SourceKittenFramework

private extension Line {
    var contentRange: NSRange {
        return NSRange(location: range.location, length: content.characters.count)
    }

    // `Line` in this rule always contains word import
    // This method returns contents of line that are after import
    private func afterImport() -> String {
        guard let range = content.range(of: "import ") else { return "" }
        return String(content.characters.suffix(from: range.upperBound))
    }

    // Case insensitive comparission of contents of the line
    // after the word `import`
    static func <= (lhs: Line, rhs: Line) -> Bool {
        return lhs.afterImport().lowercased() <= rhs.afterImport().lowercased()
    }
}

private extension Array where Element == Line {
    // Groups lines, so that lines that are one after the other
    // will end up in same group.
    func grouped() -> [[Line]] {
        return self.reduce([[Line]]()) { result, line in
            if let last = result.last?.last {
                var copy = result
                if last.index == line.index - 1 {
                    copy[copy.count - 1].append(line)
                } else {
                    copy.append([line])
                }
                return copy
            } else {
                return [[line]]
            }
        }
    }
}

    )

    public func validate(file: File) -> [StyleViolation] {
        let groups = importGroups(in: file, filterEnabled: false)
        return violatingOffsets(inGroups: groups).map { index -> StyleViolation in
            let location = Location(file: file, characterOffset: index)
            return StyleViolation(ruleDescription: type(of: self).description,
                                  severity: configuration.severity,
