From 95b9b24ec0e98622ef9e66a65a9ccc1925e8a2f1 Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Sat, 14 Dec 2024 13:33:23 +0000 Subject: [PATCH] Update linters --- .mise.toml | 4 ++-- Sources/Frontend/Commands/ScanCommand.swift | 9 +++++---- Sources/Frontend/UpdateChecker.swift | 7 ++----- Sources/PeripheryKit/Results/CheckstyleFormatter.swift | 2 +- Sources/PeripheryKit/Results/CodeClimateFormatter.swift | 4 ++-- Sources/PeripheryKit/Results/CsvFormatter.swift | 2 +- .../PeripheryKit/Results/GitHubActionsFormatter.swift | 4 ++-- Sources/PeripheryKit/Results/JsonFormatter.swift | 4 ++-- Sources/PeripheryKit/Results/OutputFormatter.swift | 2 +- Sources/PeripheryKit/Results/XcodeFormatter.swift | 2 +- 10 files changed, 19 insertions(+), 21 deletions(-) diff --git a/.mise.toml b/.mise.toml index 06a4960fd..0fb205ad0 100644 --- a/.mise.toml +++ b/.mise.toml @@ -1,3 +1,3 @@ [tools] -swiftformat = "0.54.3" -swiftlint = "0.56.2" +swiftformat = "0.55.3" +swiftlint = "0.57.1" diff --git a/Sources/Frontend/Commands/ScanCommand.swift b/Sources/Frontend/Commands/ScanCommand.swift index 1b9151170..437deae7f 100644 --- a/Sources/Frontend/Commands/ScanCommand.swift +++ b/Sources/Frontend/Commands/ScanCommand.swift @@ -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() diff --git a/Sources/Frontend/UpdateChecker.swift b/Sources/Frontend/UpdateChecker.swift index 9f74f0874..091102cdb 100644 --- a/Sources/Frontend/UpdateChecker.swift +++ b/Sources/Frontend/UpdateChecker.swift @@ -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)" diff --git a/Sources/PeripheryKit/Results/CheckstyleFormatter.swift b/Sources/PeripheryKit/Results/CheckstyleFormatter.swift index b334abfa3..7601db51e 100644 --- a/Sources/PeripheryKit/Results/CheckstyleFormatter.swift +++ b/Sources/PeripheryKit/Results/CheckstyleFormatter.swift @@ -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 [ "\n", diff --git a/Sources/PeripheryKit/Results/CodeClimateFormatter.swift b/Sources/PeripheryKit/Results/CodeClimateFormatter.swift index 7fcd54acc..6797a8aa8 100644 --- a/Sources/PeripheryKit/Results/CodeClimateFormatter.swift +++ b/Sources/PeripheryKit/Results/CodeClimateFormatter.swift @@ -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 { @@ -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) } } diff --git a/Sources/PeripheryKit/Results/CsvFormatter.swift b/Sources/PeripheryKit/Results/CsvFormatter.swift index 93fdee6af..4a365e174 100644 --- a/Sources/PeripheryKit/Results/CsvFormatter.swift +++ b/Sources/PeripheryKit/Results/CsvFormatter.swift @@ -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 { diff --git a/Sources/PeripheryKit/Results/GitHubActionsFormatter.swift b/Sources/PeripheryKit/Results/GitHubActionsFormatter.swift index f855b0a29..8cb6c2897 100644 --- a/Sources/PeripheryKit/Results/GitHubActionsFormatter.swift +++ b/Sources/PeripheryKit/Results/GitHubActionsFormatter.swift @@ -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 diff --git a/Sources/PeripheryKit/Results/JsonFormatter.swift b/Sources/PeripheryKit/Results/JsonFormatter.swift index 9bce7491b..6033657dd 100644 --- a/Sources/PeripheryKit/Results/JsonFormatter.swift +++ b/Sources/PeripheryKit/Results/JsonFormatter.swift @@ -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 { @@ -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) } } diff --git a/Sources/PeripheryKit/Results/OutputFormatter.swift b/Sources/PeripheryKit/Results/OutputFormatter.swift index 3403060e4..e72197ee9 100644 --- a/Sources/PeripheryKit/Results/OutputFormatter.swift +++ b/Sources/PeripheryKit/Results/OutputFormatter.swift @@ -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 { diff --git a/Sources/PeripheryKit/Results/XcodeFormatter.swift b/Sources/PeripheryKit/Results/XcodeFormatter.swift index 0bed933b7..6ab9acc6a 100644 --- a/Sources/PeripheryKit/Results/XcodeFormatter.swift +++ b/Sources/PeripheryKit/Results/XcodeFormatter.swift @@ -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) }