mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
Fix skipping of files when using --stdinpath
This commit is contained in:
@@ -622,9 +622,11 @@ func processArguments(_ args: [String], in directory: String) -> ExitCode {
|
||||
try serializeOptions(options, to: outputURL)
|
||||
} else {
|
||||
printRunningMessage()
|
||||
var shouldSkip = false
|
||||
if let stdinURL = options.formatOptions?.fileInfo.filePath.map(URL.init(fileURLWithPath:)) {
|
||||
do {
|
||||
try gatherOptions(&options, for: stdinURL, with: { print($0, as: .info) })
|
||||
shouldSkip = options.shouldSkipFile(stdinURL)
|
||||
} catch {
|
||||
if printWarnings([error]) {
|
||||
status = .finished(error)
|
||||
@@ -632,8 +634,10 @@ func processArguments(_ args: [String], in directory: String) -> ExitCode {
|
||||
}
|
||||
}
|
||||
}
|
||||
let output = try applyRules(input, options: options, lineRange: lineRange,
|
||||
verbose: verbose, lint: lint, reporter: reporter)
|
||||
let output = shouldSkip ? input : try applyRules(
|
||||
input, options: options, lineRange: lineRange,
|
||||
verbose: verbose, lint: lint, reporter: reporter
|
||||
)
|
||||
if let outputURL = outputURL, !useStdout {
|
||||
if (try? String(contentsOf: outputURL)) != output, !dryrun {
|
||||
do {
|
||||
|
||||
@@ -577,6 +577,20 @@ public struct FileOptions {
|
||||
self.unexcludedGlobs = unexcludedGlobs
|
||||
self.minVersion = minVersion
|
||||
}
|
||||
|
||||
public func shouldSkipFile(_ inputURL: URL) -> Bool {
|
||||
let path = inputURL.standardizedFileURL.path
|
||||
for excluded in excludedGlobs {
|
||||
guard excluded.matches(path) else {
|
||||
continue
|
||||
}
|
||||
if unexcludedGlobs.contains(where: { $0.matches(path) }) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/// All options
|
||||
@@ -603,4 +617,8 @@ public struct Options {
|
||||
self.rules = rules
|
||||
self.lint = lint
|
||||
}
|
||||
|
||||
public func shouldSkipFile(_ inputURL: URL) -> Bool {
|
||||
return fileOptions?.shouldSkipFile(inputURL) ?? false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public func enumerateFiles(withInputURL inputURL: URL,
|
||||
let queue = concurrent ? DispatchQueue.global(qos: .userInitiated) : completionQueue
|
||||
|
||||
func wasSkipped(_ inputURL: URL, with options: Options) -> Bool {
|
||||
guard shouldSkipFile(inputURL, with: options) else {
|
||||
guard options.shouldSkipFile(inputURL) else {
|
||||
return false
|
||||
}
|
||||
if let handler = skipped {
|
||||
@@ -275,33 +275,13 @@ func gatherOptions(_ options: inout Options, for inputURL: URL, with logger: Log
|
||||
var directory = URL(fileURLWithPath: inputURL.pathComponents[0]).standardized
|
||||
for part in inputURL.pathComponents.dropFirst().dropLast() {
|
||||
directory.appendPathComponent(part)
|
||||
if shouldSkipFile(directory, with: options) {
|
||||
if options.shouldSkipFile(directory) {
|
||||
return
|
||||
}
|
||||
try processDirectory(directory, with: &options, logger: logger)
|
||||
}
|
||||
}
|
||||
|
||||
// Determine if file should be skipped
|
||||
private func shouldSkipFile(_ inputURL: URL, with options: Options) -> Bool {
|
||||
guard let excludedGlobs = options.fileOptions?.excludedGlobs else {
|
||||
return false
|
||||
}
|
||||
let path = inputURL.standardizedFileURL.path
|
||||
for excluded in excludedGlobs {
|
||||
guard excluded.matches(path) else {
|
||||
continue
|
||||
}
|
||||
if let unexcluded = options.fileOptions?.unexcludedGlobs,
|
||||
unexcluded.contains(where: { $0.matches(path) })
|
||||
{
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Process configuration files in specified directory.
|
||||
private var configCache = [URL: [String: String]]()
|
||||
private let configQueue = DispatchQueue(label: "swiftformat.config", qos: .userInteractive)
|
||||
|
||||
Reference in New Issue
Block a user