Rule Request: `Bool` variable naming
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
New rule request
It is a convention to prefix Bool variables with a verb to indicate the type - usually is/are, but there could be others. Examples include UIView.isHidden, UIDeviceOrientation.isPortrait or the standard library's Collection.isEmpty.
Triggering examples:
var flipped = false
var changes = true
let empty: Bool
Non-triggering examples:
var isFlipped = false
var hasChanges = true
let isEmpty: Bool
The rule should have a list of prefixes that are allowed by default and the ability to specify more. From my experience, I'd start with is, are, has, should, can, will, did.
The rule should probably be opt-in.
I'm posting this first in case there are any red flags - I don't want to spend time developing this only to be told later that the rule won't be merged 🙂
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are named. Start by reviewing SwiftLint's existing rule implementations and configuration conventions, then determine how an opt-in Bool-naming rule and configurable prefixes should fit them. Done means the proposed behavior, defaults, configuration, and triggering and non-triggering cases are covered and accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100