From b7e150a4b7641a455d4e47d81c88aa6040319a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Hellander?= Date: Sun, 15 Oct 2023 13:25:37 +0200 Subject: [PATCH] Update SA1011 to not require space before a range operator #3708 --- .../SpacingRules/SA1011CSharp8UnitTests.cs | 20 +++++++++++++++++++ ...singSquareBracketsMustBeSpacedCorrectly.cs | 1 + 2 files changed, 21 insertions(+) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1011CSharp8UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1011CSharp8UnitTests.cs index b0ce402cb..e22a24929 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1011CSharp8UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1011CSharp8UnitTests.cs @@ -106,5 +106,25 @@ public void TestMethod(object?[] arguments) await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); } + + [Fact] + [WorkItem(3708, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3708")] + public async Task TestClosingSquareBracketFollowedByRangeAsync() + { + var testCode = @"namespace TestNamespace +{ + public class TestClass + { + public void TestMethod(int[] arg) + { + _ = arg[0]..; + _ = arg[0] ..; + } + } +} +"; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1011ClosingSquareBracketsMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1011ClosingSquareBracketsMustBeSpacedCorrectly.cs index ef77ee58f..f942f5a6c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1011ClosingSquareBracketsMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1011ClosingSquareBracketsMustBeSpacedCorrectly.cs @@ -107,6 +107,7 @@ private static void HandleCloseBracketToken(SyntaxTreeAnalysisContext context, S case SyntaxKind.OpenBracketToken: case SyntaxKind.CloseParenToken: case SyntaxKind.MinusGreaterThanToken: + case SyntaxKindEx.DotDotToken: precedesSpecialCharacter = true; break;