realm / realm/SwiftLint

Empty Array Initialize

Open
#5,156 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion rule-request
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New rule request

array initialize using [] instead ()

Bad
var emptyArray = [Int]()
Good
var emptyArray: [Int] = []
  1. using [] is more common and preferred due to its readability and simplicity. It is a more straightforward way to indicate that you are initializing an empty array of a specific type.
  2. using () to initialize an empty array might lead to confusion, as it resembles tuple syntax, which may suggest that you are creating a tuple.

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 the existing SwiftLint rule implementations and tests for syntax-style checks. Use the issue's bad and good examples to define the expected behavior for empty arrays, then add coverage showing that [] is preferred over Int. Done means the rule consistently identifies the requested form and the related tests pass.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.