SA1010 incorrectly reported on opening bracket in C# 11 list pattern
See original GitHub issue// ⚠️ SA1010 Opening square brackets should not be preceded by a space
// ↓
if (new[] { 1 } is [1])
{
}
SDK 6.0.200 or newer required. Example csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
Issue Analytics
- State:
- Created a year ago
- Reactions:7
- Comments:6 (5 by maintainers)
Top Results From Across the Web
SA1010 incorrectly reported on opening bracket in C# 11 ...
FWIW, I use patterns a fair amount in some of my projects and have quite a few StyleCop rules disabled due to bugs...
Read more >Pattern checking.check of incorrect number of operators ...
Example 1: (a+b)- has a one extra operator How do i confirm that the number of operators are incorrect. Example 2 : ((a+b)/(c-d)...
Read more >.NET Programming Standards & Reference Guide Version ...
An opening curly bracket within a C# element, statement, or expression is followed by a blank line. Rule Description. To improve the readability...
Read more >What's new in C# 11 - C# Guide
Get an overview of the new features added in C# 11. ... UTF-8 string literals; Newlines in string interpolation expressions; List patterns ......
Read more >Pattern matching using the is and switch expressions.
Discard pattern: to match any expression. List patterns: to test if sequence elements match corresponding nested patterns. Introduced in C# 11.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the example, @AArnott. The existing pull request should handle this case as well, if it gets merged.
It shows up in pattern matching within
switch
expressions as well:In the above snippet,
SA1010
appears on the[
of[0x1d
and[0x1C
.