66//
77
88import Foundation
9- import Yams
109
11- struct Linter {
12- struct Config : Decodable {
13- struct Rule : Decodable {
10+ public struct Linter {
11+ public struct Config : Decodable {
12+ public struct Rule : Decodable {
1413 let severity : Severity
1514 }
1615 let included : [ String ]
@@ -23,57 +22,54 @@ struct Linter {
2322 case rules
2423 }
2524
26- init ( ) {
25+ public init ( ) {
2726 self . included = [ ]
2827 self . excluded = [ ]
2928 self . rules = [ : ]
3029 }
3130
32- init ( url: URL ) throws {
33- let string = try String ( contentsOf: url, encoding: . utf8)
34- self = try YAMLDecoder ( ) . decode ( Config . self, from: string, userInfo: [ : ] )
35- }
36-
37- init ( from decoder: Decoder ) throws {
31+ public init ( from decoder: Decoder ) throws {
3832 let container = try decoder. container ( keyedBy: CodingKeys . self)
3933 self . included = try container. decodeIfPresent ( [ String ] . self, forKey: . included) ?? [ ]
4034 self . excluded = try container. decodeIfPresent ( [ String ] . self, forKey: . excluded) ?? [ ]
4135 self . rules = try container. decodeIfPresent ( [ String : Rule ] . self, forKey: . rules) ?? [ : ]
4236 }
4337 }
4438
45- static let fileName = " .stringray.yml "
39+ public static let fileName = " .stringray.yml "
4640
47- static let allRules : [ LintRule ] = [
41+ public static let allRules : [ LintRule ] = [
4842 MissingLocalizationLintRule ( ) ,
4943 OrphanedLocalizationLintRule ( ) ,
50- MissingPlaceholderLintRule ( )
44+ MissingPlaceholderLintRule ( ) ,
45+ MissingCommentLintRule ( )
5146 ]
5247
53- struct Error : LocalizedError {
54- var violations : [ LintRuleViolation ]
55- init ( _ violations: [ LintRuleViolation ] ) {
48+ public struct Error : LocalizedError {
49+ public private( set) var violations : [ LintRuleViolation ]
50+
51+ public init ( _ violations: [ LintRuleViolation ] ) {
5652 self . violations = violations
5753 }
5854
59- var errorDescription : String ? {
55+ public var errorDescription : String ? {
6056 let errorCount = violations. filter { $0. severity == . error } . count
6157 let warningCount = violations. filter { $0. severity == . warning } . count
6258 return " Encountered \( errorCount) errors and \( warningCount) warnings. "
6359 }
6460 }
6561
66- let rules : [ LintRule ]
62+ public let rules : [ LintRule ]
6763 private let reporter : Reporter
6864 private let config : Config
6965
70- init ( rules: [ LintRule ] = Linter . allRules, reporter: Reporter = ConsoleReporter ( ) , config: Config = Config ( ) ) {
66+ public init ( rules: [ LintRule ] = Linter . allRules, reporter: Reporter , config: Config = Config ( ) ) {
7167 self . rules = rules
7268 self . reporter = reporter
7369 self . config = config
7470 }
7571
76- private func run( on table: StringsTable , url: URL ) throws -> [ LintRuleViolation ] {
72+ private func run( on table: StringsTable , url: Foundation . URL ) throws -> [ LintRuleViolation ] {
7773 var runnableRules = self . rules
7874
7975 let includedRules = Set ( config. included)
@@ -93,7 +89,7 @@ struct Linter {
9389 }
9490 }
9591
96- func report( on table: StringsTable , url: URL ) throws {
92+ public func report( on table: StringsTable , url: Foundation . URL ) throws {
9793 let violations = try run ( on: table, url: url)
9894 var outputStream = LinterOutputStream ( fileHandle: FileHandle . standardOutput)
9995 reporter. generateReport ( for: violations, to: & outputStream)
0 commit comments