λ1003: Use this method with argument names
Methods such as Match and Switch should be called with named arguments.
Cause
A method annotated with [UseWithArgumentNames] is called and at least one argument is passed positionally.
This applies to Match and Switch on Option<T>, Either<L, R>, Result<T> and EitherOrBoth<L, R>.
Calls inside expression trees (for example an Expression<Func<...>> passed to Entity Framework) are exempt,
because named arguments are not supported there.
Reason for rule
The arguments of Match and Switch are all functions of a similar shape. Without names it is easy to
confuse which branch handles which case, and swapping two branches often compiles without error.
Naming the arguments (none:, some:, left:, right:, ok:, error:) documents the intent at the call site
and makes the order of the branches irrelevant.
How to fix violations
Add the parameter name to every argument. A code fix is available.
Examples
Disallowed
static string Example(Option<int> option)
=> option.Match(() => "none", value => value.ToString());
Allowed
static string Example(Option<int> option)
=> option.Match(
none: () => "none",
some: value => value.ToString());
Using the attribute on your own methods
The attribute is internal to Funcky, but the analyzer matches it by its full name Funcky.CodeAnalysis.UseWithArgumentNamesAttribute,
so a copy in your own assembly works just as well. Let Funcky.Analyzers generate that copy by listing the attribute in your project file:
<PropertyGroup>
<FunckyCodeAnalysisAttributes>UseWithArgumentNames</FunckyCodeAnalysisAttributes>
</PropertyGroup>
Alternatively, add the attribute by hand:
namespace Funcky.CodeAnalysis;
[AttributeUsage(AttributeTargets.Method)]
internal sealed class UseWithArgumentNamesAttribute : Attribute;
Either way, the rule then applies to every method you annotate:
[UseWithArgumentNames]
public static Money Create(decimal amount, string currency) => ...
Money.Create(amount: 10m, currency: "CHF"); // ok
Money.Create(10m, "CHF"); // λ1003
See Using the attributes in your own code for the details of the generator.