Skip to content

Commit

Permalink
Fix an issue with decoding Violation without date
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Sep 13, 2021
1 parent 584f603 commit a59cf02
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let package = Package(
.target(
name: "Core",
dependencies: [
.product(name: "BetterCodable", package: "BetterCodable"),
.product(name: "Rainbow", package: "Rainbow"),
]
),
Expand Down
1 change: 1 addition & 0 deletions Sources/Checkers/Lint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public enum Lint {
public static func runCustomScript(check: Check, command: String) throws -> LintResults {
let tempScriptFileUrl = URL(fileURLWithPath: "_\(check.id).tempscript")
try command.write(to: tempScriptFileUrl, atomically: true, encoding: .utf8)
try shellOut(to: "chmod", arguments: ["+x", tempScriptFileUrl.path])

do {
let output = try shellOut(to: "/bin/bash", arguments: [tempScriptFileUrl.path])
Expand Down
1 change: 1 addition & 0 deletions Sources/Configuration/Core+DefaultCodableStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extension Severity {
}

extension Regex {
/// Use to set the default value of `Regex` instances to `.*` in rules when users don't provide an explicit value.
public enum DefaultToMatchAllArray: DefaultCodableStrategy {
public static var defaultValue: [Regex] { [try! Regex(".*")] }
}
Expand Down
9 changes: 9 additions & 0 deletions Sources/Core/Extensions/Date+DefaultCodableStrategy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation
import BetterCodable

extension Date {
/// Use to set the default value of `Date` instances to `Date.now` in rules when users don't provide an explicit value.
public enum DefaultToNow: DefaultCodableStrategy {
public static var defaultValue: Date { Date() }
}
}
4 changes: 3 additions & 1 deletion Sources/Core/Violation.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Foundation
import BetterCodable

/// A violation found in a check.
public struct Violation: Codable, Equatable {
/// The exact time this violation was discovered. Needed for sorting purposes.
public let discoverDate: Date
@DefaultCodable<Date.DefaultToNow>
public var discoverDate: Date

/// The matched string that violates the check.
public let matchedString: String?
Expand Down

0 comments on commit a59cf02

Please sign in to comment.