Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
[Hokila](https://github.com/Hokila)
[#6897](https://github.com/realm/SwiftLint/issues/6897)

* Fix `--working-directory` having no effect. The `defer` restoring the previous
directory was scoped to the `if` block, so it ran before linting started.
[haruna-miyamoto](https://github.com/haruna-miyamoto)
[#6907](https://github.com/realm/SwiftLint/issues/6907)

## 0.65.1: Fresh Folded Fixtures

### Breaking
Expand Down
13 changes: 7 additions & 6 deletions Source/SwiftLintFramework/LintOrAnalyzeCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,14 @@ package struct LintOrAnalyzeOptions {
package struct LintOrAnalyzeCommand {
package static func run(_ options: LintOrAnalyzeOptions) async throws {
Request.disableSourceKitOverride = options.mode == .lint && options.disableSourceKit
if let workingDirectory = options.workingDirectory {
let currentDirectory = FileManager.default.currentDirectoryPath
defer {
if !FileManager.default.changeCurrentDirectoryPath(currentDirectory) {
queuedFatalError("Could not change back to the original directory '\(currentDirectory)'.")
}
var currentDirectory: String?
defer {
if let currentDirectory, !FileManager.default.changeCurrentDirectoryPath(currentDirectory) {
queuedFatalError("Could not change back to the original directory '\(currentDirectory)'.")
}
}
if let workingDirectory = options.workingDirectory {
currentDirectory = FileManager.default.currentDirectoryPath
if !FileManager.default.changeCurrentDirectoryPath(workingDirectory) {
throw SwiftLintError.usageError(
description: """
Expand Down