Skip to content

Gradually deprecate running swift-format without input paths; require '-' for stdin in the future #914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2025
Merged
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
18 changes: 17 additions & 1 deletion Sources/swift-format/Frontend/Frontend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion Sources/swift-format/Subcommands/LintFormatOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down