Skip to content

Commit 5485d35

Browse files
authored
Merge 8906e8e into a559b3e
2 parents a559b3e + 8906e8e commit 5485d35

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/MaintainabilityRules/SA1119CSharp8UnitTests.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,78 @@ public unsafe void TestMethod()
170170

171171
await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
172172
}
173+
174+
[Fact]
175+
[WorkItem(3370, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3370")]
176+
public async Task TestRangeFollowedByMemberCallAsync()
177+
{
178+
const string testCode = @"using System;
179+
180+
public class TestClass
181+
{
182+
public void TestMethod()
183+
{
184+
var array = (1..10).ToString();
185+
}
186+
}
187+
";
188+
189+
await new CSharpTest(LanguageVersion.CSharp8)
190+
{
191+
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp31,
192+
TestCode = testCode,
193+
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
194+
}
195+
196+
[Fact]
197+
[WorkItem(3370, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3370")]
198+
public async Task TestRangeAsync()
199+
{
200+
const string testCode = @"using System;
201+
202+
public class TestClass
203+
{
204+
public void TestMethod()
205+
{
206+
var a = new int[0];
207+
var b = a[(..)];
208+
var range = (1..10);
209+
}
210+
}
211+
";
212+
213+
const string fixedCode = @"using System;
214+
215+
public class TestClass
216+
{
217+
public void TestMethod()
218+
{
219+
var a = new int[0];
220+
var b = a[..];
221+
var range = 1..10;
222+
}
223+
}
224+
";
225+
226+
DiagnosticResult[] expected =
227+
{
228+
Diagnostic(DiagnosticId).WithSpan(8, 19, 8, 23),
229+
Diagnostic(ParenthesesDiagnosticId).WithLocation(8, 19),
230+
Diagnostic(ParenthesesDiagnosticId).WithLocation(8, 22),
231+
Diagnostic(DiagnosticId).WithSpan(9, 21, 9, 28),
232+
Diagnostic(ParenthesesDiagnosticId).WithLocation(9, 21),
233+
Diagnostic(ParenthesesDiagnosticId).WithLocation(9, 27),
234+
};
235+
236+
var test = new CSharpTest(LanguageVersion.CSharp8)
237+
{
238+
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp31,
239+
TestCode = testCode,
240+
FixedCode = fixedCode,
241+
};
242+
test.ExpectedDiagnostics.AddRange(expected);
243+
244+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
245+
}
173246
}
174247
}

StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ private static void HandleParenthesizedExpression(SyntaxNodeAnalysisContext cont
117117
&& !node.Expression.IsKind(SyntaxKind.CoalesceExpression)
118118
&& !node.Expression.IsKind(SyntaxKind.QueryExpression)
119119
&& !node.Expression.IsKind(SyntaxKind.AwaitExpression)
120+
&& !node.Expression.IsKind(SyntaxKindEx.RangeExpression)
120121
&& !node.IsKind(SyntaxKind.ConstructorDeclaration))
121122
{
122123
if (node.Expression.IsKind(SyntaxKind.ConditionalAccessExpression)

0 commit comments

Comments
 (0)