swiftlint_fix
Run SwiftLint in auto-correction mode to automatically fix violations that have safe, mechanical corrections. This tool modifies your source files in place, applying fixes for issues like trailing whitespace, missing colons, vertical whitespace, and other formatting rules. Violations that cannot be safely auto-corrected are reported but left unchanged.
Parameters
Section titled “Parameters”| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
path | string | No | Current directory | Absolute path to the file or directory to fix |
config | string | No | Auto-detected .swiftlint.yml | Absolute path to a custom SwiftLint configuration file |
Usage Examples
Section titled “Usage Examples”Fix the entire project
Section titled “Fix the entire project”“Auto-fix all SwiftLint violations in my FitnessTracker project”
{ "path": "/Users/dev/Projects/FitnessTracker"}Fix a specific file
Section titled “Fix a specific file”“Fix lint issues in my APIClient file”
{ "path": "/Users/dev/Projects/FitnessTracker/FitnessTracker/Services/APIClient.swift"}Fix with a custom configuration
Section titled “Fix with a custom configuration”“Run SwiftLint auto-fix using the team’s config”
{ "path": "/Users/dev/Projects/FitnessTracker", "config": "/Users/dev/Projects/FitnessTracker/.swiftlint.yml"}Example Output
Section titled “Example Output”Running SwiftLint auto-correction...
Corrected: /Users/dev/Projects/FitnessTracker/FitnessTracker/ViewModels/WorkoutViewModel.swift - trailing_whitespace (3 occurrences) - vertical_whitespace (1 occurrence)
/Users/dev/Projects/FitnessTracker/FitnessTracker/Views/WorkoutDetailView.swift - colon (2 occurrences) - trailing_whitespace (1 occurrence)
/Users/dev/Projects/FitnessTracker/FitnessTracker/Models/Workout.swift - opening_brace (1 occurrence) - trailing_semicolon (1 occurrence)
Remaining (not auto-correctable): /Users/dev/Projects/FitnessTracker/FitnessTracker/Views/WorkoutDetailView.swift:34:5: warning: Force Cast Violation: Force casts should be avoided (force_cast)
/Users/dev/Projects/FitnessTracker/FitnessTracker/Services/APIClient.swift:89:45: error: Force Try Violation: Force tries should be avoided (force_try)
Summary: 8 violations corrected in 3 files, 2 violations remainingRelated Tools
Section titled “Related Tools”swiftlint_run— Run a read-only lint check first to see all violations before fixingswift_format_run— Apply swift-format for additional formatting correctionsbuild_warnings— Check for compiler warnings after fixing lint issues