Skip to content

swift_format_run

Run Apple’s swift-format tool on your Swift source files to check and enforce consistent code formatting. Unlike SwiftLint which focuses on code style rules and best practices, swift-format specifically handles whitespace, indentation, line breaks, and structural formatting according to a defined style. This tool reports formatting deviations and can process files recursively.

ParameterTypeRequiredDefaultDescription
pathstringYesAbsolute path to the file or directory to format-check
recursivebooleanNotrueWhether to process directories recursively

“Run swift-format on my FitnessTracker project”

{
"path": "/Users/dev/Projects/FitnessTracker/FitnessTracker"
}

“Check the formatting of my WorkoutService file”

{
"path": "/Users/dev/Projects/FitnessTracker/FitnessTracker/Services/WorkoutService.swift",
"recursive": false
}

Check only the top-level directory without recursing

Section titled “Check only the top-level directory without recursing”

“Run swift-format on just the files in the Sources root, not subdirectories”

{
"path": "/Users/dev/Projects/FitnessTracker/Sources",
"recursive": false
}

“Check formatting on all test files”

{
"path": "/Users/dev/Projects/FitnessTracker/FitnessTrackerTests"
}
Running swift-format...
/Users/dev/Projects/FitnessTracker/FitnessTracker/Services/WorkoutService.swift:
Line 14: Indentation uses 3 spaces, expected 4 spaces
Line 28: Missing blank line between function declarations
Line 45: Opening brace should be on the same line as the declaration
/Users/dev/Projects/FitnessTracker/FitnessTracker/ViewModels/ProfileViewModel.swift:
Line 9: Trailing comma missing in multiline collection literal
Line 22: Line length exceeds 100 characters (currently 118)
/Users/dev/Projects/FitnessTracker/FitnessTracker/Models/UserProfile.swift:
Line 5: Import statements should be sorted alphabetically
Summary: 6 formatting issues in 3 files (47 files checked)

When all files pass:

Running swift-format...
All 47 files pass formatting checks. No issues found.
  • swiftlint_run — Check for style and best-practice violations beyond formatting
  • swiftlint_fix — Auto-correct SwiftLint violations after fixing formatting
  • build_warnings — Check for compiler warnings alongside formatting issues