You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to propose a new rule explicit_default_argument which would trigger a violation if an argument passed to a function or initializer matches the default value provided by the function (or init).
Would trigger violations in both lines as they are called with the same values as their defaults. Calling Foo(bar: false, baz: "baz") would not trigger the rule.
This allows for cleaner, more concise code on the call site, especially if there are many default parameters.
letfoo=Foo(bar: false)
foo.doSomething()
Should the rule be configurable, if so what parameters should be configurable?
If any, I suggest adding two params, for excluding initializers and excluding functions, both set to false by default.
Should the rule be opt-in or enabled by default? Why?
My suggestion is to set the rule as opt-in. It's a style enhancement, not a functional one.
The text was updated successfully, but these errors were encountered:
This requires to implement an Analyzer rule, because the rule needs to access the method/initializer declaration from the call-side to figure out the default parameter values. This is impossible on a syntax-level only.
New Issue Checklist
New rule request
I would like to propose a new rule
explicit_default_argument
which would trigger a violation if an argument passed to a function or initializer matches the default value provided by the function (or init).Given the following code:
When calling:
Would trigger violations in both lines as they are called with the same values as their defaults. Calling
Foo(bar: false, baz: "baz")
would not trigger the rule.This allows for cleaner, more concise code on the call site, especially if there are many default parameters.
If any, I suggest adding two params, for excluding initializers and excluding functions, both set to
false
by default.My suggestion is to set the rule as opt-in. It's a style enhancement, not a functional one.
The text was updated successfully, but these errors were encountered: