Skip to content

Fix crash when running Lint from LegacyMain #267

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

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ as well as the following command line options:
files in any directories listed on the command line and their descendants.
Without this flag, it is an error to list a directory on the command line.

* `-s/--strict`: If specified, exits non-zero code if one or more warning are found.
This option only works in lint mode.

### Configuration

For any source file being checked or formatted, `swift-format` looks for a
Expand Down
8 changes: 1 addition & 7 deletions Sources/swift-format/Subcommands/Lint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ extension SwiftFormatCommand {

@OptionGroup()
var lintOptions: LintFormatOptions

@Flag(
name: .shortAndLong,
help: "Fail on warnings."
)
var strict: Bool = false

func run() throws {
let frontend = LintFrontend(lintFormatOptions: lintOptions)
frontend.run()
if frontend.errorsWereEmitted { throw ExitCode.failure }
if strict,
if lintOptions.strict,
frontend.diagnosticEngine.diagnostics
.contains(where: { $0.message.severity == .warning }) {
throw ExitCode.failure
Expand Down
5 changes: 5 additions & 0 deletions Sources/swift-format/Subcommands/LintFormatOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ struct LintFormatOptions: ParsableArguments {
help: "Process files in parallel, simultaneously across multiple cores.")
var parallel: Bool = false

@Flag(
name: .shortAndLong,
help: "Fail on warnings.")
var strict: Bool = false

/// The list of paths to Swift source files that should be formatted or linted.
@Argument(help: "Zero or more input filenames.")
var paths: [String] = []
Expand Down