<commit_before>//
//  ClassVisibilityRule.swift
//  SwiftLint
//
//  Created by <NAME> on 8/3/16.
//  Copyright © 2016 Realm. All rights reserved.
//

import Foundation
import SourceKittenFramework

private extension AccessControlLevel {
    init?(_ dictionary: [String: SourceKitRepresentable]) {
        guard let
            accessibility = dictionary["key.accessibility"] as? String,
            acl = AccessControlLevel(rawValue: accessibility)
            else { return nil }
        self = acl
    }
}

func superclass(dictionary: [String: SourceKitRepresentable]) -> String? {
    typealias SKArray = [SourceKitRepresentable]
    typealias SKDict = [String: SourceKitRepresentable]
    guard let
        kindString = dictionary["key.kind"] as? String,
        kind = SwiftDeclarationKind(rawValue: kindString)
        where kind == .Class
        else { return nil }
    guard let
        inheritedTypes = dictionary["key.inheritedtypes"] as? SKArray,
        className = (inheritedTypes[0] as? SKDict)?["key.name"] as? String
        else { return nil }
    return className
}

public class FooTest: NSObject {  }

public struct PrivateUnitTestRule: ASTRule, ConfigurationProviderRule {

    public var configuration: PrivateUnitTestConfiguration = {
        var configuration = PrivateUnitTestConfiguration(identifier: "private_unit_test")
        configuration.message = "Unit test marked `private` will not be run by XCTest."
        configuration.regex = regex("XCTestCase")
        return configuration
    }()

    public init() {}

    public static let description = RuleDescription(
        identifier: "private_unit_test",
        name: "Private Unit Test",
        description: "Unit tests marked private are silently skipped.",
        nonTriggeringExamples: [
            "class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
            "}",
            "internal class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
            "}",
            "public class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
            "}"
        ],
        triggeringExamples: [
            "private ↓class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
                "private func test4() {}\n " +
            "}",
            "class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
                "private ↓func test4() {}\n " +
            "}",
            "internal class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
                "private ↓func test4() {}\n " +
            "}",
            "public class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
                "private ↓func test4() {}\n " +
            "}",
        ]<commit_msg>Add unit test for issue #786<commit_after>//
//  ClassVisibilityRule.swift
//  SwiftLint
//
//  Created by <NAME> on 8/3/16.
//  Copyright © 2016 Realm. All rights reserved.
//

import Foundation
import SourceKittenFramework

private extension AccessControlLevel {
    init?(_ dictionary: [String: SourceKitRepresentable]) {
        guard let
            accessibility = dictionary["key.accessibility"] as? String,
            acl = AccessControlLevel(rawValue: accessibility)
            else { return nil }
        self = acl
    }
}

func superclass(dictionary: [String: SourceKitRepresentable]) -> String? {
    typealias SKArray = [SourceKitRepresentable]
    typealias SKDict = [String: SourceKitRepresentable]
    guard let
        kindString = dictionary["key.kind"] as? String,
        kind = SwiftDeclarationKind(rawValue: kindString)
        where kind == .Class
        else { return nil }
    guard let
        inheritedTypes = dictionary["key.inheritedtypes"] as? SKArray,
        className = (inheritedTypes[0] as? SKDict)?["key.name"] as? String
        else { return nil }
    return className
}

public class FooTest: NSObject {  }

public struct PrivateUnitTestRule: ASTRule, ConfigurationProviderRule {

    public var configuration: PrivateUnitTestConfiguration = {
        var configuration = PrivateUnitTestConfiguration(identifier: "private_unit_test")
        configuration.message = "Unit test marked `private` will not be run by XCTest."
        configuration.regex = regex("XCTestCase")
        return configuration
    }()

    public init() {}

    public static let description = RuleDescription(
        identifier: "private_unit_test",
        name: "Private Unit Test",
        description: "Unit tests marked private are silently skipped.",
        nonTriggeringExamples: [
            "class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
            "}",
            "internal class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
            "}",
            "public class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
            "}",
            // Non-test classes
            "private class Foo: NSObject { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
            "}",
            "private class Foo { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
            "}"
        ],
        triggeringExamples: [
            "private ↓class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
                "private func test4() {}\n " +
            "}",
            "class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
                "private ↓func test4() {}\n " +
            "}",
            "internal class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
                "private ↓func test4() {}\n " +
            "}",
            "public class FooTest: XCTestCase { " +
                "func test1() {}\n " +
                "internal func test2() {}\n " +
                "public func test3() {}\n " +
                "private ↓func test4() {}\n " +
            "}",
        ]
{'fraction_non_alphanumeric': 0.12788948160306388, 'fraction_numerical': 0.010532074955546436, 'mean_word_length': 1.6754482253933407, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5709657', 'n_tokens_mistral': 2087, 'n_tokens_neox': 1968, 'n_words': 552}