realm / realm/SwiftLint

Add option to the `explicit_self` rule to only enforce using self in initializers

Open
#2,436 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Continued from https://github.com/realm/SwiftLint/issues/321.

I would like to see an option to only enforce self in initializers. I generally prefer using implicit self, but in initializers, it makes more sense to use self for consistency, as some properties might need self to differentiate them from the initializer arguments.

To illustrate, I would like to enforce:

class Unicorn {
	init(foo: String, goat: String) {
		self.foo = foo
		bar = goat
	}
}

To be:

class Unicorn {
	init(foo: String, goat: String) {
		self.foo = foo
		self.bar = goat
	}
}

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 with the existing explicit_self rule, its configuration, and its tests. Add coverage for an initializer-only option using the two examples in the issue, and consider the work done when the rule enforces self in initializers without changing behavior elsewhere.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.