realm / realm/SwiftLint

Rule Request: `allowed_prefix_symbols` configuration in `identifier_name`

Open
#3,682 0 comments 3 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

New Issue Checklist
New rule request

When validates_start_with_lowercase is true, all identifier names must start with a lowercase character.
This will trigger a violation even if the name starts with a symbol, for example and underscore _.

The only way to achieve this now is to disable validates_start_with_lowercase, but it would be nice to have to option to allow certain prefix symbols, eg:

identifier_name:
  allowed_prefix_symbols: ["_"]
  validates_start_with_lowercase: true

The above would trigger a violation for:

var MyVar: String

...but would not trigger a violation for:

private var _myVar: String

While naming properties this way shouldn't be the norm, sometimes it can serve as raw value storage for a computed property of the same name. For example:

private var _myVar: Int?

@objc
public var myVar: Int {
    get { 
         _myVar ?? -1
    }
    set { 
        _myVar = newValue < 0 ? nil : newValue
    }
}

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 locating SwiftLint’s identifier_name rule and its configuration handling, then trace how validates_start_with_lowercase checks the first character. Add coverage for allowed_prefix_symbols using the shown _myVar and MyVar cases, and confirm the option’s behavior in the rule’s existing tests.

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
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.