Skip to content

Commit

Permalink
Describe the rules
Browse files Browse the repository at this point in the history
  • Loading branch information
nicorichard committed Jun 15, 2024
1 parent 24499da commit 2dfb1df
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/StringCatalogValidator/Model/ExtractionState.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public enum ExtractionState: String {
public enum ExtractionState: String, CaseIterable {
case automatic
case manual
case extracted_with_value
Expand Down
5 changes: 5 additions & 0 deletions Sources/StringCatalogValidator/Model/LocalizationState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum LocalizationState: String, CaseIterable {
case translated
case needs_review
case stale
}
1 change: 1 addition & 0 deletions Sources/StringCatalogValidator/Rule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public protocol Rule {
typealias Failure = Validator.Reason

static var name: String { get }
static var description: String { get }

var severity: Severity { get set }
func validate(key: String, value: Entry) -> [Failure]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ extension Rules {
public struct RequireExtractionState: Rule {
let states: [String]
public var severity: Severity = .error

public static let name = "require-extraction-state"
public static let description: String = "Requires that each key's extraction state matches one of the provided values. Known extractions states: \(ExtractionState.allCases.map({"`\($0)`"}).joined(separator: ", "))"

public init(in states: [String]) {
self.states = states
Expand Down Expand Up @@ -38,6 +40,7 @@ extension Rules {
let states: [String]
public var severity: Severity = .error
public static let name = "reject-extraction-state"
public static let description: String = "Rejects an entry if it's extraction state matchs any of the provided values. Known extractions states: \(ExtractionState.allCases.map({"`\($0)`"}).joined(separator: ", "))"

public init(state: String?) {
self.states = [state ?? Self.defaultExtractionState]
Expand Down
1 change: 1 addition & 0 deletions Sources/StringCatalogValidator/Rules/RequireLocales.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extension Rules {
let locales: [String]
public var severity: Severity = .error
public static let name = "require-locale"
public static let description: String = "Requires that each key contains localizations for the provided locale values."

public init(in locales: [String]) {
self.locales = locales
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extension Rules {
let states: [String]
public var severity: Severity = .error
public static let name = "require-localization-state"
public static let description: String = "Requires that each localization's state matches one of the provided values. Know localization states: " + LocalizationState.allCases.map({"`\($0)`"}).joined(separator: ", ")

public init(in states: [String]) {
self.states = states
Expand Down Expand Up @@ -55,6 +56,7 @@ extension Rules {
let states: [String]
public var severity: Severity = .error
public static let name = "reject-localization-state"
public static let description: String = "Rejects a localization if it's state matches one of the provided values. Know localization states: " + LocalizationState.allCases.map({"`\($0)`"}).joined(separator: ", ")

public init(in states: [String]) {
self.states = states
Expand Down
2 changes: 1 addition & 1 deletion Sources/XCStringsLint/XCStringsLint+Rules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension XCStringsLint {
let padding = alignment - $0.name.count

let namePad = String(repeating: " ", count: padding)
print($0.name + namePad + "Description") // TODO: Describe the rules
print($0.name + namePad + $0.description)

let configPad = String(repeating: " ", count: alignment)
print("\(configPad)`value`, `values`")
Expand Down

0 comments on commit 2dfb1df

Please sign in to comment.