Repository navigation
Open
Labels
enhancementIdeas for improvements of existing features and rules.
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Feature Request
Description
The indentation_width rule currently does not support autocorrection (--fix). This makes it tedious to fix indentation violations manually, especially in larger codebases or when refactoring code.
According to the official documentation, the rule explicitly states:
- Supports autocorrection: No
Motivation
Indentation issues are purely formatting-related and should be safe to autocorrect. Other style rules like trailing_whitespace already support autocorrection. Adding autocorrection for indentation_width would:
- Save developers significant time fixing indentation manually
- Make the rule more practical for teams to enable
- Align with the behavior of other formatting-focused rules
Steps to Reproduce
- Create a file with incorrect indentation:
// IndentationTest.swift
import SwiftUI
struct TestView: View {
var body: some View {
HStack {
Text("Hello")
}
.frame(maxWidth: .infinity)
.onTapGesture {
if true {
Task { @MainActor in
try await doSomething() // Wrong indentation
}
}
}
}
func doSomething() async throws {}
}- Run SwiftLint lint:
$ swiftlint lint IndentationTest.swiftOutput:
IndentationTest.swift:13:1: error: Indentation Width Violation: Code should be indented using one tab or 4 spaces (indentation_width)
- Attempt to fix with
--fix:
$ swiftlint --fix IndentationTest.swiftOutput:
Correcting Swift files at paths IndentationTest.swift
Correcting 'IndentationTest.swift' (1/1)
Done correcting 1 file!
- Run lint again - the
indentation_widthviolation still exists:
$ swiftlint lint IndentationTest.swiftOutput:
IndentationTest.swift:13:1: error: Indentation Width Violation: Code should be indented using one tab or 4 spaces (indentation_width)
Expected Behavior
Running swiftlint --fix should automatically correct indentation violations by adjusting the whitespace at the beginning of lines to match the expected indentation level.
Environment
- SwiftLint version: 0.63.2
- Installation method: Pre-built binary
- Xcode version: 16.x
- macOS version: macOS 15.x (Sequoia)
Reacted by Genevieve Luyt and Azonaz
Metadata
Metadata
Assignees
Labels
enhancementIdeas for improvements of existing features and rules.
Activity
Add autocorrection support to indentation_width rule
Add autocorrection support to indentation_width rule
Add autocorrection support to indentation_width rule
Update Changelog duplicate (+14 squashed commits)
Add autocorrection support to indentation_width rule