realm / realm/SwiftLint

Rule request: Enforce only tabs OR spaces

Open
#3,839 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

rule-request
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New Issue Checklist
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing SwiftLint's existing indentation_width rule and reproduce the behavior with the test.swift example using the shown swiftlint command. Define how indentation_style configuration should select tabs or spaces, then add coverage for mixed indentation and verify the resulting warnings and default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.