Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp10.SpacingRules
{
using StyleCop.Analyzers.Test.CSharp9.SpacingRules;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
{
using System.Threading;
Expand Down Expand Up @@ -32,7 +30,7 @@ public class Foo
{
public void TestMethod()
{
var values = (new[] { 3} , new[] { 3} );
var values = (new[] { 3{|#0:}|} , new[] { 3{|#1:}|} );
}
}";
const string fixedCode = @"using System;
Expand All @@ -47,8 +45,8 @@ public void TestMethod()

DiagnosticResult[] expected =
{
Diagnostic().WithLocation(7, 32).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(7, 45).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(0).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(1).WithArguments(string.Empty, "preceded"),
};

await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -65,12 +63,12 @@ public unsafe void TestMethod()
{
int* data1 = stackalloc int[] { 1 , 1 } ;
int* data2 = stackalloc int[] { 1 , 1 };
int* data3 = stackalloc int[] { 1 , 1} ;
int* data4 = stackalloc int[] { 1 , 1};
int* data3 = stackalloc int[] { 1 , 1{|#0:}|} ;
int* data4 = stackalloc int[] { 1 , 1{|#1:}|};
int* data5 = stackalloc int[] { 1 , 1
};
int* data6 = stackalloc int[]
{ 1 , 1};
{ 1 , 1{|#2:}|};
int* data7 = stackalloc int[]
{
1 , 1 } ;
Expand Down Expand Up @@ -103,9 +101,9 @@ public unsafe void TestMethod()

DiagnosticResult[] expected =
{
Diagnostic().WithArguments(string.Empty, "preceded").WithLocation(9, 50),
Diagnostic().WithArguments(string.Empty, "preceded").WithLocation(10, 50),
Diagnostic().WithArguments(string.Empty, "preceded").WithLocation(14, 20),
Diagnostic().WithLocation(0).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(1).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(2).WithArguments(string.Empty, "preceded"),
};

await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -122,12 +120,12 @@ public unsafe void TestMethod()
{
int* data1 = stackalloc[] { 1 , 1 } ;
int* data2 = stackalloc[] { 1 , 1 };
int* data3 = stackalloc[] { 1 , 1} ;
int* data4 = stackalloc[] { 1 , 1};
int* data3 = stackalloc[] { 1 , 1{|#0:}|} ;
int* data4 = stackalloc[] { 1 , 1{|#1:}|};
int* data5 = stackalloc[] { 1 , 1
};
int* data6 = stackalloc[]
{ 1 , 1};
{ 1 , 1{|#2:}|};
int* data7 = stackalloc[]
{
1 , 1 } ;
Expand Down Expand Up @@ -160,9 +158,9 @@ public unsafe void TestMethod()

DiagnosticResult[] expected =
{
Diagnostic().WithArguments(string.Empty, "preceded").WithLocation(9, 46),
Diagnostic().WithArguments(string.Empty, "preceded").WithLocation(10, 46),
Diagnostic().WithArguments(string.Empty, "preceded").WithLocation(14, 20),
Diagnostic().WithLocation(0).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(1).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(2).WithArguments(string.Empty, "preceded"),
};

await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
{
using System.Threading;
Expand Down Expand Up @@ -43,7 +41,7 @@ public void TestMethod(object value)
break;

// The space before 'message' is checked
case Exception { Message: { }message }:
case Exception { Message: { {|#0:}|}message }:
break;
}
}
Expand All @@ -67,7 +65,7 @@ public void TestMethod(object value)
}
}";

var expected = Diagnostic().WithSpan(14, 37, 14, 38).WithArguments(string.Empty, "followed");
var expected = Diagnostic().WithLocation(0).WithArguments(string.Empty, "followed");
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp9.SpacingRules
{
using StyleCop.Analyzers.Test.CSharp8.SpacingRules;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.SpacingRules
{
using System.Threading;
Expand Down Expand Up @@ -54,15 +52,17 @@ public async Task TestStringInterpolationAsync()
{
public class TestClass
{
public void TestMethod()
public void TestMethod(int a, int b)
{
var test = 2;
var x = $""{test}"";
x = $""{test}"";
x = $""({test})"";
x = $""({test} )"";
x = $""{test }"";
x = $""{test } "";
x = $""{test {|#0:}|}"";
x = $""{test {|#1:}|} "";
x = $""{new { a, b{|#2:}|}}"";
x = $""{new { a, b } {|#3:}|}"";
}
}
}
Expand All @@ -72,7 +72,7 @@ public void TestMethod()
{
public class TestClass
{
public void TestMethod()
public void TestMethod(int a, int b)
{
var test = 2;
var x = $""{test}"";
Expand All @@ -81,15 +81,19 @@ public void TestMethod()
x = $""({test} )"";
x = $""{test}"";
x = $""{test} "";
x = $""{new { a, b }}"";
x = $""{new { a, b }}"";
}
}
}
";

DiagnosticResult[] expected =
{
Diagnostic().WithLocation(12, 25).WithArguments(" not", "preceded"),
Diagnostic().WithLocation(13, 25).WithArguments(" not", "preceded"),
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
Diagnostic().WithLocation(1).WithArguments(" not", "preceded"),
Diagnostic().WithLocation(2).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(3).WithArguments(" not", "preceded"),
};

await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -107,7 +111,7 @@ public async Task TestPropertyDeclarationAsync()
public class TestClass
{
public int TestProperty1 { get; set; }
public int TestProperty2 { get; set;}
public int TestProperty2 { get; set;{|#0:}|}
}
}
";
Expand All @@ -124,7 +128,7 @@ public class TestClass

DiagnosticResult[] expected =
{
Diagnostic().WithLocation(6, 45).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(0).WithArguments(string.Empty, "preceded"),
};

await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -146,9 +150,9 @@ public class TestClass
public void TestMethod()
{
new Dictionary<int, int> { { 1, 1 } };
new Dictionary<int, int> { { 1, 1} };
new Dictionary<int, int> { { 1, 1 }};
new Dictionary<int, int> { { 1, 1}};
new Dictionary<int, int> { { 1, 1{|#0:}|} };
new Dictionary<int, int> { { 1, 1 {|#1:}|}{|#2:}|};
new Dictionary<int, int> { { 1, 1{|#3:}|}{|#4:}|};
}
}
}
Expand All @@ -173,12 +177,12 @@ public void TestMethod()

DiagnosticResult[] expected =
{
Diagnostic().WithLocation(10, 46).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(11, 47).WithArguments(string.Empty, "followed"),
Diagnostic().WithLocation(11, 48).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(12, 46).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(12, 46).WithArguments(string.Empty, "followed"),
Diagnostic().WithLocation(12, 47).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(0).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(1).WithArguments(string.Empty, "followed"),
Diagnostic().WithLocation(2).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(3).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(3).WithArguments(string.Empty, "followed"),
Diagnostic().WithLocation(4).WithArguments(string.Empty, "preceded"),
};

await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
Expand Down Expand Up @@ -297,9 +301,9 @@ public void TestMethod1(object[] a)
public void TestMethod2()
{
TestMethod1(new object[] { });
TestMethod1(new object[] {});
TestMethod1(new object[] {{|#0:}|});
TestMethod1(new object[] { } );
TestMethod1(new object[] {} );
TestMethod1(new object[] {{|#1:}|} );
}
}
}
Expand Down Expand Up @@ -327,8 +331,8 @@ public void TestMethod2()
// space between closing brace and closing parenthesis should be reported by SA1009
DiagnosticResult[] expected =
{
Diagnostic().WithLocation(12, 39).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(14, 39).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(0).WithArguments(string.Empty, "preceded"),
Diagnostic().WithLocation(1).WithArguments(string.Empty, "preceded"),
};

await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
Expand Down Expand Up @@ -383,12 +387,12 @@ public async Task TestMissingTokenAsync()
{
string testCode = @"
class ClassName
{
{{|#0:|}
";

DiagnosticResult[] expected =
{
DiagnosticResult.CompilerError("CS1513").WithMessage("} expected").WithLocation(3, 2),
DiagnosticResult.CompilerError("CS1513").WithMessage("} expected").WithLocation(0),
};

await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private static void HandleCloseBraceToken(SyntaxTreeAnalysisContext context, Syn
|| (nextToken.IsKind(SyntaxKind.QuestionToken) && nextToken.GetNextToken(includeZeroWidth: true).IsKind(SyntaxKind.DotToken))
|| nextToken.IsKind(SyntaxKind.CloseBracketToken)
|| (nextToken.IsKind(SyntaxKind.ColonToken) && nextToken.Parent.IsKind(SyntaxKindEx.CasePatternSwitchLabel))
|| (nextToken.IsKind(SyntaxKind.ExclamationToken) && nextToken.Parent.IsKind(SyntaxKindEx.SuppressNullableWarningExpression));
|| (nextToken.IsKind(SyntaxKind.ExclamationToken) && nextToken.Parent.IsKind(SyntaxKindEx.SuppressNullableWarningExpression))
|| (nextToken.IsKind(SyntaxKind.CloseBraceToken) && nextToken.Parent.IsKind(SyntaxKind.Interpolation));
}
else
{
Expand Down