Rule request: [first_element] enforce .first instead of [0] on arrays to prevent data races
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
- Why should this rule be added?
When accessing the first element of an array there could be potential data races when doing so via [0] instead of .first (and handling the potential nil value)
- Provide several examples of what would and wouldn't trigger violations.
-
array[0] will trigger
-
array.first? won't
-
Should the rule be configurable, if so what parameters should be configurable?
N/A -
Should the rule be opt-in or enabled by default? Why?
Not sure about this one, opt-in probably as it gives more flexibility
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
Start by reviewing SwiftLint's existing rule implementations and tests to find the entry points for a new rule. Define how array[0] should be reported while array.first? should not, and resolve whether the rule is opt-in before implementation. Done means the requested examples are covered and the rule's configuration behavior is tested.
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