Rule request: Enforce only tabs OR spaces
New Issue Checklist
- [x] Updated SwiftLint to the latest version
- [x] I searched for existing GitHub issues
New rule request
As this is in my eyes a pretty obvious thing, please just close if there's an existing rule for this. I searched extensively and didn't find a rule or existing issue.
As far as I can tell, the indentation_width rule only enforces use of consistent amount of spaces or tabs. However, depending on an editor's set tab width, this can lead to inconsistent indentation when one developer uses tabs, another spaces. So SwiftLint should enforce that only one style of indentation is used (and preferably enforce tabs, of course 😬).
Should trigger warning (as GitHub uses a tab width of eight, it's even easy to see here):
private func test() {
print("One Tab")
print("Four Spaces")
}
Current output:
$ swiftlint --version
0.46.2
$ swiftlint --enable-all-rules test.swift
Linting Swift files at paths test.swift
Linting 'test.swift' (1/1)
Done linting! Found 0 violations, 0 serious in 1 file.
I think this should be opt-out, by default it should warn when mixing tabs and spaces, and one should be able to configure what shall be used something like this:
indentation_style: tabs -> warn when indenting with spaces
indentation_style: spaces -> warn when indenting with tabs
It would be best if this was correctable, similar to the trailing_whitespace rule. But it would probably have to know how many spaces equals a tab.
I started work on a project a while ago where all the files were a mix of tabs and spaces. I think most of the previous devs had used spaces but one had used tabs, which affected a lot of files. I fixed this using multi-file find/replace in Xcode but having a swiftlint rule that fixed this would have been great. I used the trailing_whitespace rule to fix all the trailing whitespace in the project.