realm / realm/SwiftLint

Rule Request: [container_types] Need new rule to require idiomatic container rules

Open
#1,808 2 comments 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
Rule Request

The "idiomatically-correct" types of containers are ContainerType<ElementType[, ElementType...]>. While the Swift documentation states that the syntactic sugar versions are preferred, there are points in the code where the sugar versions do not work because the idiomatically-correct type is required (Array<Int>.Index is valid, [Int].Index is an error).

The existing rule for syntactic_sugar rule disallows these or simply doesn't check (on/off). There needs to be a new rule (that deprecates syntactic_sugar) that allows checking for idiomatically-correct, syntactic sugar, or off.

  • container_types **on** - type definitions of Array<Int> or Dictionary<String, Any> would pass, [Int] and [String: Any] would fail.
  • container_types **sugar** - type definitions of [Int] or [String: Any] would pass, Array<Int> and Dictionary<String, Any> would fail.
  • container_types **off** - type definitions of [Int], '[String: Any], Array, or Dictionary<String, Any>` would pass.

Default would be container_types sugar to match existing syntactic_sugar default of on. This would also require syntactic_sugar to be deprecated or mapped into this new rule as a synonym to 'sugar' or 'off'.

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

The issue does not name files or tests. Start by locating the existing syntactic_sugar rule and its configuration handling, then review how SwiftLint rules are tested. Done means container_types supports on, sugar, and off modes, with the requested default and syntactic_sugar compatibility behavior.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.