diff --git a/Source/swiftlint/Commands/LintCommand.swift b/Source/swiftlint/Commands/LintCommand.swift index f9afc805dce..16b824826d4 100644 --- a/Source/swiftlint/Commands/LintCommand.swift +++ b/Source/swiftlint/Commands/LintCommand.swift @@ -44,8 +44,8 @@ struct LintCommand: CommandProtocol { linter.file.invalidateCache() reporter.reportViolations(currentViolations, realtimeCondition: true) }.flatMap { files in - if LintCommand.isWarningThresholdBroken(configuration, violations: violations) { - violations.append(LintCommand.createThresholdViolation(configuration.warningThreshold!)) + if LintCommand.isWarningThresholdBroken(configuration: configuration, violations: violations) { + violations.append(LintCommand.createThresholdViolation(threshold: configuration.warningThreshold!)) reporter.reportViolations([violations.last!], realtimeCondition: true) } reporter.reportViolations(violations, realtimeCondition: false) @@ -83,14 +83,14 @@ struct LintCommand: CommandProtocol { ) } - private static func isWarningThresholdBroken(_ configuration: Configuration, + private static func isWarningThresholdBroken(configuration: Configuration, violations: [StyleViolation]) -> Bool { guard let warningThreshold = configuration.warningThreshold else { return false } let numberOfWarningViolations = violations.filter({ $0.severity == .warning }).count return numberOfWarningViolations >= warningThreshold } - private static func createThresholdViolation(_ threshold: Int) -> StyleViolation { + private static func createThresholdViolation(threshold: Int) -> StyleViolation { let description = RuleDescription( identifier: "warning_threshold", name: "Warning Threshold", diff --git a/Source/swiftlint/Commands/RulesCommand.swift b/Source/swiftlint/Commands/RulesCommand.swift index 2c681aefec0..da905a383b7 100644 --- a/Source/swiftlint/Commands/RulesCommand.swift +++ b/Source/swiftlint/Commands/RulesCommand.swift @@ -11,7 +11,21 @@ import Result import SwiftLintFramework import SwiftyTextTable -private let violationMarker = "↓" +private func print(ruleDescription desc: RuleDescription) { + print("\(desc.consoleDescription)") + + if !desc.triggeringExamples.isEmpty { + func indent(_ string: String) -> String { + return string.components(separatedBy: "\n") + .map { " \($0)" } + .joined(separator: "\n") + } + print("\nTriggering Examples (violation is marked with '↓'):") + for (index, example) in desc.triggeringExamples.enumerated() { + print("\nExample #\(index + 1)\n\n\(indent(example))") + } + } +} struct RulesCommand: CommandProtocol { let verb = "rules" @@ -23,7 +37,7 @@ struct RulesCommand: CommandProtocol { return .failure(.usageError(description: "No rule with identifier: \(ruleID)")) } - printRuleDescript(rule.description) + print(ruleDescription: rule.description) return .success() } @@ -31,22 +45,6 @@ struct RulesCommand: CommandProtocol { print(TextTable(ruleList: masterRuleList, configuration: configuration).render()) return .success() } - - fileprivate func printRuleDescript(_ desc: RuleDescription) { - print("\(desc.consoleDescription)") - - if !desc.triggeringExamples.isEmpty { - func indent(_ string: String) -> String { - return string.components(separatedBy: "\n") - .map { " \($0)" } - .joined(separator: "\n") - } - print("\nTriggering Examples (violation is marked with '\(violationMarker)'):") - for (index, example) in desc.triggeringExamples.enumerated() { - print("\nExample #\(index + 1)\n\n\(indent(example))") - } - } - } } struct RulesOptions: OptionsProtocol {