realm / realm/SwiftLint

Rule request: [first_element] enforce .first instead of [0] on arrays to prevent data races

Open
#4,555 1 comment 0 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
  1. 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)

  1. Provide several examples of what would and wouldn't trigger violations.
  • array[0] will trigger

  • array.first? won't

  1. Should the rule be configurable, if so what parameters should be configurable?
    N/A

  2. 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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.