Skip to content

Commit

Permalink
Fix lint changes that would not work on older swift version
Browse files Browse the repository at this point in the history
  • Loading branch information
f-meloni committed Oct 14, 2024
1 parent bfa468d commit 1f7286b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 24 deletions.
8 changes: 5 additions & 3 deletions Sources/Danger/DangerDSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ public struct DangerDSL: Decodable {

// Setup the OctoKit once all other
if runningOnGithub {
let config = if let baseURL = settings.github.baseURL {
TokenConfiguration(settings.github.accessToken, url: baseURL)
let config: TokenConfiguration

if let baseURL = settings.github.baseURL {
config = TokenConfiguration(settings.github.accessToken, url: baseURL)
} else {
TokenConfiguration(settings.github.accessToken)
config = TokenConfiguration(settings.github.accessToken)
}

github.api = Octokit(config)
Expand Down
12 changes: 7 additions & 5 deletions Sources/Danger/GitDiff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,16 @@ struct DiffParser {
let filePath = lines.first?.split(separator: " ").first(where: { $0.starts(with: "b/") })?
.deletingPrefix("b/") ?? ""

let change: FileDiff.ParsedHeader.ChangeType = if lines.contains(where: { $0.hasPrefix("deleted file mode ") }) {
.deleted
let change: FileDiff.ParsedHeader.ChangeType

if lines.contains(where: { $0.hasPrefix("deleted file mode ") }) {
change = .deleted
} else if lines.contains(where: { $0.hasPrefix("new file mode") }) {
.created
change = .created
} else if let modifiedLineIndex = lines.firstIndex(where: { $0.hasPrefix("rename from ") }) {
.renamed(oldPath: lines[modifiedLineIndex].deletingPrefix("rename from "))
change = .renamed(oldPath: lines[modifiedLineIndex].deletingPrefix("rename from "))
} else {
.modified
change = .modified
}

return FileDiff.ParsedHeader(filePath: filePath, change: change)
Expand Down
8 changes: 5 additions & 3 deletions Sources/Danger/Report.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ public extension DangerDSL {

/// Adds an inline suggestion to the Danger report (sends a normal message if suggestions are not supported)
func suggestion(code: String, file: String, line: Int) {
let message: String = if dangerRunner.dsl.supportsSuggestions {
"""
let message: String

if dangerRunner.dsl.supportsSuggestions {
message = """
```suggestion
\(code)
```
"""
} else {
code
message = code
}

globalResults.markdowns.append(Violation(message: message, file: file, line: line))
Expand Down
8 changes: 5 additions & 3 deletions Sources/DangerDependenciesResolver/PackageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ public struct PackageManager {
func addPackage(_ package: InlineDependenciesFinder.InlineDependency) throws {
let name = try packageDataProvider.nameOfPackage(at: package.url, temporaryFolder: temporaryFolder)

let latestVersion: Int = if let major = package.major {
major
let latestVersion: Int

if let major = package.major {
latestVersion = major
} else {
try packageDataProvider.latestMajorVersionForPackage(at: package.url)
latestVersion = try packageDataProvider.latestMajorVersionForPackage(at: package.url)
}
let package = Package(name: name,
url: absoluteRepositoryURL(from: package.url),
Expand Down
8 changes: 5 additions & 3 deletions Sources/DangerShellExecutor/ShellExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ public struct ShellExecutor: ShellExecuting {
environmentVariables: [String: String],
outputFile: String?) -> Process
{
let scriptOutputFile = if let outputFile {
" > \(outputFile)"
let scriptOutputFile: String

if let outputFile {
scriptOutputFile = " > \(outputFile)"
} else {
""
scriptOutputFile = ""
}

let script = "\(command) \(arguments.joined(separator: " "))" + scriptOutputFile
Expand Down
10 changes: 6 additions & 4 deletions Sources/Runner/Commands/Edit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import RunnerLib

func editDanger(version dangerSwiftVersion: String, logger: Logger) throws {
let fileManager = FileManager.default
let dangerfilePath: String = if let dangerfileArgumentPath = DangerfilePathFinder.dangerfilePath() {
dangerfileArgumentPath.fullPath
let dangerfilePath: String

if let dangerfileArgumentPath = DangerfilePathFinder.dangerfilePath() {
dangerfilePath = dangerfileArgumentPath.fullPath
} else {
(Runtime.getDangerfile() ?? "Dangerfile.swift").fullPath
dangerfilePath = (Runtime.getDangerfile() ?? "Dangerfile.swift").fullPath
}

if !fileManager.fileExists(atPath: dangerfilePath) {
createDangerfile(dangerfilePath)
}

let absoluteLibPath: String
let libsImport: [String]

Expand Down
8 changes: 5 additions & 3 deletions Sources/Runner/MarathonScriptManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import Logger
func getScriptManager(forDangerSwiftVersion dangerSwiftVersion: String,
logger: Logger) throws -> ScriptManager
{
let homeFolder: String = if #available(OSX 10.12, *) {
FileManager.default.homeDirectoryForCurrentUser.path
let homeFolder: String

if #available(OSX 10.12, *) {
homeFolder = FileManager.default.homeDirectoryForCurrentUser.path
} else {
NSHomeDirectory()
homeFolder = NSHomeDirectory()
}

let folder = "\(homeFolder)/.danger-swift/"
Expand Down

0 comments on commit 1f7286b

Please sign in to comment.