New Issue Checklist
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.swift
Output:
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.swift
Output:
Correcting Swift files at paths IndentationTest.swift
Correcting 'IndentationTest.swift' (1/1)
Done correcting 1 file!
- Run lint again - the
indentation_width violation still exists:
$ swiftlint lint IndentationTest.swift
Output:
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)
New Issue Checklist
Feature Request
Description
The
indentation_widthrule 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:
Motivation
Indentation issues are purely formatting-related and should be safe to autocorrect. Other style rules like
trailing_whitespacealready support autocorrection. Adding autocorrection forindentation_widthwould:Steps to Reproduce
Output:
--fix:Output:
indentation_widthviolation still exists:Output:
Expected Behavior
Running
swiftlint --fixshould automatically correct indentation violations by adjusting the whitespace at the beginning of lines to match the expected indentation level.Environment