Skip to content

Rule Request: [Constructor Parameters Count] #4217

Open

Description

@wedkarz

New Issue Checklist

New rule request

The idea is pretty simple: to put a warning where more than X arguments are used in the constructor.
The X value should be a parameter with some reasonable default (5?).
One could also think about parametrizing whether we apply the rule to all types or just to classes. Some DTO structs may be fragile, yet we can always use // swiftlint:disable in such cases.

  1. Why should this rule be added? It is a common rule used by static analyzer tools, and is a rule that limits the responsibilities of class and keeps it small.
  2. Provide several examples of what would and wouldn't trigger violations.

Using more than 5 parameters would trigger a warning.

init(dependencyA parent: DependencyA,
       with dependencyB: DependencyB,
       dependencyC: DependencyC,
       dependencyD: DependencyD,
       dependencyE: DependencyE,
dependencyF: DependencyF)

Using "just" 5 parameters would be ok.

init(dependencyA parent: DependencyA,
       with dependencyB: DependencyB,
       dependencyC: DependencyC,
       dependencyD: DependencyD,
       dependencyE: DependencyE)
  1. Should the rule be configurable, if so what parameters should be configurable? max parameters that are allowed without warning
  2. Should the rule be opt-in or enabled by default? Why? opt-in

Activity

  1. added
    rule-request
    on Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    rule-request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions