Skip to content

tuple-element-names-in-signatures

C#styleno fixdefault: offcsharp/stylecop

Reports a tuple type in the signature of a method, constructor, property, indexer, conversion operator or delegate whose elements have no names. Overrides and implementations of interface members are not reported, since their names are not the member’s to choose. No fix.

A caller sees (int, int) in the signature and Item1 and Item2 in the result, so it has to read the body to know which is which. Names ((int Width, int Height)) make the signature the documentation.

To fix, name the elements.

Reported
...
namespace A.B {
...
struct S { }
interface I { (int, int) Pair(); }
class P { public virtual void Run() { } }
class Q : P, I {
public (int, int) Pair() => (1, 2);
public (int, int) Other() => (1, 2);
...
After the fix
...
namespace A.B {
...
struct S { }
interface I { (int, int) Pair(); }
class P { public virtual void Run() { } }
class Q : P, I {
public (int, int) Pair() => (1, 2);
public (int, int) Other() => (1, 2);
...
csharp:
lint:
rules:
tuple-element-names-in-signatures: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line tuple-element-names-in-signatures in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1414 full