<commit_before>//
//  ConditionalBindingCascadeRule.swift
//  SwiftLint
//
//  Created by <NAME> on 08/01/2016.
//  Copyright © 2016 Realm. All rights reserved.
//

import Foundation
import SourceKittenFramework

public struct ConditionalBindingCascadeRule: ConfigurationProviderRule {

    public var configuration = SeverityConfiguration(.Warning)

    public init() {}

    public static let description = RuleDescription(
        identifier: "conditional_binding_cascade",
        name: "Conditional Binding Cascade",
        description: "Repeated `let` statements in conditional binding cascade should be avoided.",
        nonTriggeringExamples: [
            "if let a = b, c = d {",
            "if let a = b, \n c = d {",
            "if let a = b, \n c = d \n {",
            "if let a = b { if let c = d {",
            "if let a = b { let c = d({ foo in ... })",
            "guard let a = b, c = d else {",
            "guard let a = b where a, let c = d else {"
        ],
        triggeringExamples: [
            "if let a = b, let c = d {",
            "if let a = b, \n let c = d {",
            "if let a = b, c = d, let e = f {",
            "if let a = b, let c = d \n {",
            "if \n let a = b, let c = d {",
            "if let a = b, c = d.indexOf({$0 == e}), let f = g {",
            "guard let a = b, let c = d else {"
        ]
    )

    public func validateFile(file: File) -> [StyleViolation] {
        return file.matchPattern("^(if|guard)(.*?)let(.*?),(.*?)let(.*?)\\{",
            excludingSyntaxKinds: SyntaxKind.commentAndStringKinds()).filter {<commit_msg>Add false negative example to ConditionalBindingCascadeRule<commit_after>//
//  ConditionalBindingCascadeRule.swift
//  SwiftLint
//
//  Created by <NAME> on 08/01/2016.
//  Copyright © 2016 Realm. All rights reserved.
//

import Foundation
import SourceKittenFramework

public struct ConditionalBindingCascadeRule: ConfigurationProviderRule {

    public var configuration = SeverityConfiguration(.Warning)

    public init() {}

    public static let description = RuleDescription(
        identifier: "conditional_binding_cascade",
        name: "Conditional Binding Cascade",
        description: "Repeated `let` statements in conditional binding cascade should be avoided.",
        nonTriggeringExamples: [
            "if let a = b, c = d {",
            "if let a = b, \n c = d {",
            "if let a = b, \n c = d \n {",
            "if let a = b { if let c = d {",
            "if let a = b { let c = d({ foo in ... })",
            "guard let a = b, c = d else {",
            "guard let a = b where a, let c = d else {"
        ],
        triggeringExamples: [
            "if let a = b, let c = d {",
            "if let a = b, \n let c = d {",
            "if let a = b, c = d, let e = f {",
            "if let a = b, let c = d \n {",
            "if \n let a = b, let c = d {",
            "if let a = b, c = d.indexOf({$0 == e}), let f = g {",
            "guard let a = b, let c = d else {",
            "if let a = a, b = b {\ndebugPrint(\"\")\n}\nif let c = a, let d = b {\n}",
        ]
    )

    public func validateFile(file: File) -> [StyleViolation] {
        return file.matchPattern("^(if|guard)(.*?)let(.*?),(.*?)let(.*?)\\{",
            excludingSyntaxKinds: SyntaxKind.commentAndStringKinds()).filter {
{'fraction_non_alphanumeric': 0.14435459718478585, 'fraction_numerical': 0.007786762503743636, 'mean_word_length': 1.8942807625649913, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3872678', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1019, 'n_words': 369}