Skip to content

Commit

Permalink
Update linters
Browse files Browse the repository at this point in the history
  • Loading branch information
ileitch committed Dec 14, 2024
1 parent 14005cf commit 95b9b24
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[tools]
swiftformat = "0.54.3"
swiftlint = "0.56.2"
swiftformat = "0.55.3"
swiftlint = "0.57.1"
9 changes: 5 additions & 4 deletions Sources/Frontend/Commands/ScanCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,14 @@ struct ScanCommand: FrontendCommand {
try data.write(to: baselinePath.url)
}

let output = try configuration.outputFormat.formatter.init(configuration: configuration).format(filteredResults)
if let output = try configuration.outputFormat.formatter.init(configuration: configuration).format(filteredResults) {
if configuration.outputFormat.supportsAuxiliaryOutput {
logger.info("", canQuiet: true)
}

if configuration.outputFormat.supportsAuxiliaryOutput {
logger.info("", canQuiet: true)
logger.info(output, canQuiet: false)
}

logger.info(output, canQuiet: false)
logger.endInterval(interval)

updateChecker.notifyIfAvailable()
Expand Down
7 changes: 2 additions & 5 deletions Sources/Frontend/UpdateChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ final class UpdateChecker {
else {
var json = "N/A"

if let data {
let decoded = String(decoding: data, as: UTF8.self)
if !decoded.isEmpty {
json = decoded
}
if let data, let decoded = String(bytes: data, encoding: .utf8) {
json = decoded
}

let message = "Failed to identify latest release tag in: \(json)"
Expand Down
2 changes: 1 addition & 1 deletion Sources/PeripheryKit/Results/CheckstyleFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class CheckstyleFormatter: OutputFormatter {
self.configuration = configuration
}

func format(_ results: [ScanResult]) -> String {
func format(_ results: [ScanResult]) -> String? {
let parts = results.flatMap { describe($0, colored: false) }
return [
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<checkstyle version=\"4.3\">",
Expand Down
4 changes: 2 additions & 2 deletions Sources/PeripheryKit/Results/CodeClimateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class CodeClimateFormatter: OutputFormatter {
self.configuration = configuration
}

func format(_ results: [PeripheryKit.ScanResult]) throws -> String {
func format(_ results: [ScanResult]) throws -> String? {
var jsonObject: [Any] = []

for result in results {
Expand Down Expand Up @@ -49,6 +49,6 @@ final class CodeClimateFormatter: OutputFormatter {
}

let data = try JSONSerialization.data(withJSONObject: jsonObject, options: [.prettyPrinted, .withoutEscapingSlashes])
return String(decoding: data, as: UTF8.self)
return String(bytes: data, encoding: .utf8)
}
}
2 changes: 1 addition & 1 deletion Sources/PeripheryKit/Results/CsvFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class CsvFormatter: OutputFormatter {
self.configuration = configuration
}

func format(_ results: [ScanResult]) -> String {
func format(_ results: [ScanResult]) -> String? {
var lines = ["Kind,Name,Modifiers,Attributes,Accessibility,IDs,Location,Hints"]

for result in results {
Expand Down
4 changes: 2 additions & 2 deletions Sources/PeripheryKit/Results/GitHubActionsFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ final class GitHubActionsFormatter: OutputFormatter {
self.configuration = configuration
}

func format(_ results: [ScanResult]) throws -> String {
guard !results.isEmpty else { return "" }
func format(_ results: [ScanResult]) throws -> String? {
guard !results.isEmpty else { return nil }
guard configuration.relativeResults else { throw PeripheryError.usageError("`periphery scan` must be ran with `--relative-results` when using the GitHub Actions formatter") }

return results.flatMap { result in
Expand Down
4 changes: 2 additions & 2 deletions Sources/PeripheryKit/Results/JsonFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class JsonFormatter: OutputFormatter {
self.configuration = configuration
}

func format(_ results: [ScanResult]) throws -> String {
func format(_ results: [ScanResult]) throws -> String? {
var jsonObject: [Any] = []

for result in results {
Expand Down Expand Up @@ -48,6 +48,6 @@ final class JsonFormatter: OutputFormatter {
}

let data = try JSONSerialization.data(withJSONObject: jsonObject, options: [.prettyPrinted, .withoutEscapingSlashes])
return String(decoding: data, as: UTF8.self)
return String(bytes: data, encoding: .utf8)
}
}
2 changes: 1 addition & 1 deletion Sources/PeripheryKit/Results/OutputFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public protocol OutputFormatter: AnyObject {
var currentFilePath: FilePath { get }

init(configuration: Configuration)
func format(_ results: [ScanResult]) throws -> String
func format(_ results: [ScanResult]) throws -> String?
}

extension OutputFormatter {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PeripheryKit/Results/XcodeFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class XcodeFormatter: OutputFormatter {
self.configuration = configuration
}

func format(_ results: [ScanResult]) throws -> String {
func format(_ results: [ScanResult]) throws -> String? {
guard !results.isEmpty else {
return colorize("* ", .boldGreen) + colorize("No unused code detected.", .bold)
}
Expand Down

0 comments on commit 95b9b24

Please sign in to comment.