From 3f041ed056c57fbca631bfe7fa4770fd0372316c Mon Sep 17 00:00:00 2001 From: TTOzzi Date: Sun, 12 Jan 2025 06:27:05 +0900 Subject: [PATCH] Gradually deprecate running swift-format without input paths; require '-' for stdin in the future --- Sources/swift-format/Frontend/Frontend.swift | 18 +++++++++++++++++- .../Subcommands/LintFormatOptions.swift | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Sources/swift-format/Frontend/Frontend.swift b/Sources/swift-format/Frontend/Frontend.swift index a3ea18a4f..b0e262a94 100644 --- a/Sources/swift-format/Frontend/Frontend.swift +++ b/Sources/swift-format/Frontend/Frontend.swift @@ -97,7 +97,23 @@ class Frontend { /// Runs the linter or formatter over the inputs. final func run() { - if lintFormatOptions.paths.isEmpty { + if lintFormatOptions.paths == ["-"] { + processStandardInput() + } else if lintFormatOptions.paths.isEmpty { + diagnosticsEngine.emitWarning( + """ + Running swift-format without input paths is deprecated and will be removed in the future. + + Please update your invocation to do either of the following: + + - Pass `-` to read from stdin (e.g., `cat MyFile.swift | swift-format -`). + - Pass one or more paths to Swift source files or directories containing + Swift source files. When passing directories, make sure to include the + `--recursive` flag. + + For more information, use the `--help` option. + """ + ) processStandardInput() } else { processURLs( diff --git a/Sources/swift-format/Subcommands/LintFormatOptions.swift b/Sources/swift-format/Subcommands/LintFormatOptions.swift index 520eaf970..737de42fc 100644 --- a/Sources/swift-format/Subcommands/LintFormatOptions.swift +++ b/Sources/swift-format/Subcommands/LintFormatOptions.swift @@ -108,7 +108,7 @@ struct LintFormatOptions: ParsableArguments { var experimentalFeatures: [String] = [] /// The list of paths to Swift source files that should be formatted or linted. - @Argument(help: "Zero or more input filenames.") + @Argument(help: "Zero or more input filenames. Use `-` for stdin.") var paths: [String] = [] @Flag(help: .hidden) var debugDisablePrettyPrint: Bool = false