question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New rules for tuple types

See original GitHub issue

Normally I would propose the new rules individually, but in this case I believe the individual rules are closely related and likely need to be implemented as a group.

📝 All of the following rules are automatically disabled if the project does not support C# 7 or newer.

SA1141: Use tuple syntax

Category: Readability

This rule catches three cases:

  1. Prefer (T1, T2) to ValueTuple<T1, T2>
  2. Prefer (value1, value2) to ValueTuple.Create(value1, value2)
  3. Prefer (value1, value2) to new ValueTuple<T1, T2>(value1, value2)

📝 As an aside, it appears the new tuple type syntax is not allowed inside pattern matching so it needs to be tested.

SA1414: Tuple types in signatures should have element names

Category: Maintainability

Tuple types appearing in element signatures should have explicitly named tuple elements.

SA1142: Refer to tuple elements by name

Category: Readability

This rule reports diagnostics when a tuple field is referenced by its metadata name (Item1, etc.) when a name has been provided.

SA1316: Tuple element names should start with a lowercase uppercase lowercase letter

Category: Naming

Tuple element names should be in camelCase PascalCase camelCase.

This rule will have a configuration option to analyze implicit names (C# 7.1). In the default configuration, only explicitly-provided names would be analyzed.

SA1317: Tuple element names in signatures should match

Category: Naming

See dotnet/roslyn#20850 See #1949

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
appel1commented, Nov 20, 2018

@sharwell I hope you can still make this configurable. For us it makes sense to keep the naming convention the same for all public fields and properties. Very odd to make an exception for just named value tuple fields, the ItemN fields are still pascal cased even.

2reactions
sharwellcommented, Nov 20, 2018

Based on the updated conclusion in dotnet/corefx, I’ve updated the rules above to again suggest camelCase naming. This is consistent will all cases of tuple usage I’ve observed to date.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tuple types - C# reference
Tuple types support the == and != operators. These operators compare members of the left-hand operand with the corresponding members of the ...
Read more >
Documentation - TypeScript 4.0
Variadic tuple types enable a lot of new exciting patterns, especially around function composition. ... There are a few rules when using labeled...
Read more >
Rules for tuple types, parameter t…
Use parenthesized expressions to create tuples and to pass arguments to a function call. If there is only one value inside the parenthesized...
Read more >
Exploring use cases for TypeScript tuples
In this tutorial, we will cover some real-world use cases and applications for working with named tuples in TypeScript.
Read more >
Python Tuples
Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found