<commit_before>//
//  File+SwiftLint.swift
//  SwiftLint
//
//  Created by <NAME> on 2015-05-16.
//  Copyright (c) 2015 Realm. All rights reserved.
//

import SourceKittenFramework
import SwiftXPC

internal typealias Line = (index: Int, content: String)

extension File {
    public func regions() -> [Region] {
        let nsStringContents = contents as NSString
        let commands = matchPattern("swiftlint:(enable|disable)\\ [^\\s]+",
            withSyntaxKinds: [.Comment]).flatMap { Command(string: nsStringContents, range: $0) }
        let totalNumberOfLines = lines.count
        let numberOfCharactersInLastLine = lines.last?.content.characters.count
        var regions = [Region]()
        var disabledRules = Set<String>()
        let commandPairs = zip(commands, Array(commands.dropFirst().map({Optional($0)})) + [nil])
        for (command, nextCommand) in commandPairs {
            switch command.action {
            case .Disable: disabledRules.insert(command.ruleIdentifier)
            case .Enable: disabledRules.remove(command.ruleIdentifier)
            }
            regions.append(
                Region(
                    start: Location(file: path,
                        line: command.line,
                        character: command.character),
                    end: Location(file: path,
                        line: nextCommand?.line ?? totalNumberOfLines,
                        character: nextCommand?.character ?? numberOfCharactersInLastLine),
                    disabledRuleIdentifiers: disabledRules)
            )
        }<commit_msg>Remove duplicated Line declaration<commit_after>//
//  File+SwiftLint.swift
//  SwiftLint
//
//  Created by <NAME> on 2015-05-16.
//  Copyright (c) 2015 Realm. All rights reserved.
//

import SourceKittenFramework
import SwiftXPC

extension File {
    public func regions() -> [Region] {
        let nsStringContents = contents as NSString
        let commands = matchPattern("swiftlint:(enable|disable)\\ [^\\s]+",
            withSyntaxKinds: [.Comment]).flatMap { Command(string: nsStringContents, range: $0) }
        let totalNumberOfLines = lines.count
        let numberOfCharactersInLastLine = lines.last?.content.characters.count
        var regions = [Region]()
        var disabledRules = Set<String>()
        let commandPairs = zip(commands, Array(commands.dropFirst().map({Optional($0)})) + [nil])
        for (command, nextCommand) in commandPairs {
            switch command.action {
            case .Disable: disabledRules.insert(command.ruleIdentifier)
            case .Enable: disabledRules.remove(command.ruleIdentifier)
            }
            regions.append(
                Region(
                    start: Location(file: path,
                        line: command.line,
                        character: command.character),
                    end: Location(file: path,
                        line: nextCommand?.line ?? totalNumberOfLines,
                        character: nextCommand?.character ?? numberOfCharactersInLastLine),
                    disabledRuleIdentifiers: disabledRules)
            )
        }
{'fraction_non_alphanumeric': 0.10402042118698149, 'fraction_numerical': 0.008934269304403318, 'mean_word_length': 2.1008902077151337, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1552945', 'n_tokens_mistral': 821, 'n_tokens_neox': 768, 'n_words': 190}