Skip to content

Rule Request: disallow_default_parameter #6488

Closed

Description

@CrownedPhoenix

New Issue Checklist

New Rule Request

(Dis)allow default args in functions based on their access level.

Why?

I've often run into cases where a bug slips in because a parameter is not properly forwarded down to the layer that needs it because the compiler doesn't inform me that the argument is necessary for a particular function.
To combat this, I've made a rule of thumb for myself not to use default arguments on private or internal functions so that the compiler will force me to be explicit about how the functions should be parameterized.

This works well internal to a package because I think it's reasonable to expect the maintainers/developers to know enough about the internals of the package to know how to parameterize functions appropriately. Default arguments are very useful for consumers of the public API though.

Example

Triggering

// Depending on configuration
private func foo(_: Int = 5) {}
internal func bar(n: UInt = 1000) -> String { /* ... */ }
package  func bar(n: UInt = 1000) -> String { /* ... */ }

Non-triggering

public func foo(n: UInt = 100) -> String { /* ... */ }

Configurations

  • Which access levels to trigger for (private, internal package)

Opt In?

Yes - opt-in. It doesn't feel like a hard and fast swift convention - rather something that I've personally been bitten by after years of Swift development.

Activity

  1. changed the title [-]Rule Request: default_arg_access_level[/-] [+]Rule Request: disallow_default_args[/+] on Feb 10, 2026
  2. changed the title [-]Rule Request: disallow_default_args[/-] [+]Rule Request: disallow_default_parameter[/+] on Feb 10, 2026
  3. added
    good first issue
    rule-request
    on Feb 10, 2026
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

    good first issuerule-request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions