Skip to content

Commit af6fa6e

Browse files
committed
Merge branch 'master' into testing-library
2 parents a77c8b6 + a7d874c commit af6fa6e

19 files changed

Lines changed: 408 additions & 194 deletions

StyleCop.Analyzers/StyleCop.Analyzers.Status.Generator/SolutionReader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private string GetStatus(INamedTypeSymbol classSymbol, SyntaxNode root, Semantic
262262

263263
// We use the fact that the only parameter that returns a boolean is the one we are interested in
264264
var enabledByDefaultParameter = from argument in initializer.ArgumentList.Arguments
265-
where model.GetTypeInfo(argument.Expression).Type == this.booleanType
265+
where Equals(model.GetTypeInfo(argument.Expression).Type, this.booleanType)
266266
select argument.Expression;
267267
var parameter = enabledByDefaultParameter.FirstOrDefault();
268268
string parameterString = parameter.ToString();
@@ -296,7 +296,7 @@ private IEnumerable<DiagnosticDescriptor> GetDescriptor(INamedTypeSymbol classSy
296296

297297
var noCodeFixAttribute = classSymbol
298298
.GetAttributes()
299-
.SingleOrDefault(x => x.AttributeClass == this.noCodeFixAttributeTypeSymbol);
299+
.SingleOrDefault(x => Equals(x.AttributeClass, this.noCodeFixAttributeTypeSymbol));
300300

301301
bool hasCodeFix = noCodeFixAttribute == null;
302302
if (!hasCodeFix)
@@ -356,7 +356,7 @@ private bool InheritsFrom(INamedTypeSymbol declaration, INamedTypeSymbol possibl
356356
{
357357
while (declaration != null)
358358
{
359-
if (declaration == possibleBaseType)
359+
if (declaration.Equals(possibleBaseType))
360360
{
361361
return true;
362362
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/ObjectPools/ObjectPoolTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace StyleCop.Analyzers.Test.HelperTests.ObjectPools
77
using StyleCop.Analyzers.Helpers.ObjectPools;
88
using Xunit;
99

10+
[Collection(nameof(SequentialTestCollection))]
1011
public class ObjectPoolTests
1112
{
1213
[Fact]

StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/ObjectPools/SharedPoolsTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace StyleCop.Analyzers.Test.HelperTests.ObjectPools
1010
using StyleCop.Analyzers.Helpers.ObjectPools;
1111
using Xunit;
1212

13+
[Collection(nameof(SequentialTestCollection))]
1314
public class SharedPoolsTests
1415
{
1516
[Fact]

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1313UnitTests.cs

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ public void MethodName()
382382
}
383383

384384
[Fact]
385-
[WorkItem(1343, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1343")]
386-
public async Task TestLambdaParameterMultipleUnderscoresAsync()
385+
[WorkItem(1606, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1606")]
386+
public async Task TestLambdaParameterNamedDoubleUnderscoreAsync()
387387
{
388388
var testCode = @"public class TypeName
389389
{
@@ -395,11 +395,49 @@ public void MethodName()
395395
}
396396
}";
397397

398+
await VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
399+
}
400+
401+
/// <summary>
402+
/// Verifies this diagnostic does not check whether or not a parameter named <c>__</c> is being used.
403+
/// </summary>
404+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
405+
[Fact]
406+
[WorkItem(1606, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1606")]
407+
public async Task TestLambdaParameterNamedDoubleUnderscoreUsageAsync()
408+
{
409+
var testCode = @"public class TypeName
410+
{
411+
public void MethodName()
412+
{
413+
System.Func<int, int> function1 = __ => __;
414+
System.Func<int, int> function2 = (__) => __;
415+
System.Func<int, int> function3 = delegate(int __) { return __; };
416+
}
417+
}";
418+
419+
await VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
420+
}
421+
422+
[Fact]
423+
[WorkItem(1343, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1343")]
424+
public async Task TestLambdaParameterWithThreeUnderscoresAsync()
425+
{
426+
var testCode = @"public class TypeName
427+
{
428+
public void MethodName()
429+
{
430+
System.Action<int> action1 = ___ => { };
431+
System.Action<int> action2 = (___) => { };
432+
System.Action<int> action3 = delegate(int ___) { };
433+
}
434+
}";
435+
398436
DiagnosticResult[] expected =
399437
{
400-
Diagnostic().WithArguments("__").WithLocation(5, 38),
401-
Diagnostic().WithArguments("__").WithLocation(6, 39),
402-
Diagnostic().WithArguments("__").WithLocation(7, 51),
438+
Diagnostic().WithArguments("___").WithLocation(5, 38),
439+
Diagnostic().WithArguments("___").WithLocation(6, 39),
440+
Diagnostic().WithArguments("___").WithLocation(7, 51),
403441
};
404442
await VerifyCSharpFixAsync(testCode, expected, testCode, CancellationToken.None).ConfigureAwait(false);
405443
}
@@ -419,6 +457,21 @@ public void MethodName(int _)
419457
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
420458
}
421459

460+
[Fact]
461+
[WorkItem(1606, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1606")]
462+
public async Task TestMethodParameterNamedDoubleUnderscoreAsync()
463+
{
464+
var testCode = @"public class TypeName
465+
{
466+
public void MethodName(int __)
467+
{
468+
}
469+
}";
470+
471+
DiagnosticResult expected = Diagnostic().WithArguments("__").WithLocation(3, 32);
472+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
473+
}
474+
422475
[Fact]
423476
[WorkItem(1529, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1529")]
424477
public async Task TestInheritedInterfacesWithOverloadedMembersAsync()

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1137UnitTests.cs

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ void MethodName()
15021502
}
15031503
15041504
break;
1505-
}
1505+
}
15061506
default:
15071507
label5a:
15081508
label5b:
@@ -1524,6 +1524,7 @@ void MethodName()
15241524
Diagnostic().WithLocation(34, 1),
15251525
Diagnostic().WithLocation(35, 1),
15261526
Diagnostic().WithLocation(36, 1),
1527+
Diagnostic().WithLocation(43, 1),
15271528
Diagnostic().WithLocation(44, 1),
15281529
Diagnostic().WithLocation(45, 1),
15291530
Diagnostic().WithLocation(46, 1),
@@ -1939,5 +1940,79 @@ void ZeroAlignmentMethod()
19391940

19401941
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
19411942
}
1943+
1944+
[Fact]
1945+
[WorkItem(2747, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2747")]
1946+
public async Task VerifyInitializerBracesAreCheckedAndFixedAsync()
1947+
{
1948+
var testCode = @"
1949+
using System.Collections.Generic;
1950+
1951+
public class TestClass
1952+
{
1953+
public void TestMethod()
1954+
{
1955+
List<int> testObject1 = new List<int>
1956+
{
1957+
1,
1958+
};
1959+
1960+
TestClass2 testObject2 = new TestClass2
1961+
{
1962+
Test = 1,
1963+
};
1964+
1965+
var testObject3 = new
1966+
{
1967+
TestValue = 1,
1968+
};
1969+
}
1970+
1971+
private class TestClass2
1972+
{
1973+
public int Test { get; set; }
1974+
}
1975+
}
1976+
";
1977+
1978+
var fixedCode = @"
1979+
using System.Collections.Generic;
1980+
1981+
public class TestClass
1982+
{
1983+
public void TestMethod()
1984+
{
1985+
List<int> testObject1 = new List<int>
1986+
{
1987+
1,
1988+
};
1989+
1990+
TestClass2 testObject2 = new TestClass2
1991+
{
1992+
Test = 1,
1993+
};
1994+
1995+
var testObject3 = new
1996+
{
1997+
TestValue = 1,
1998+
};
1999+
}
2000+
2001+
private class TestClass2
2002+
{
2003+
public int Test { get; set; }
2004+
}
2005+
}
2006+
";
2007+
2008+
DiagnosticResult[] expected =
2009+
{
2010+
Diagnostic().WithLocation(11, 1),
2011+
Diagnostic().WithLocation(16, 1),
2012+
Diagnostic().WithLocation(21, 1),
2013+
};
2014+
2015+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
2016+
}
19422017
}
19432018
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test
5+
{
6+
using Xunit;
7+
8+
/// <summary>
9+
/// Defines a collection for tests which cannot run in parallel with other tests.
10+
/// </summary>
11+
[CollectionDefinition(nameof(SequentialTestCollection), DisableParallelization = true)]
12+
internal sealed class SequentialTestCollection
13+
{
14+
}
15+
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpecialRules/SA0002UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace NamespaceName { }
2929
[Fact]
3030
public async Task TestMissingSettingsAsync()
3131
{
32-
await VerifyCSharpDiagnosticAsync(TestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
32+
await VerifyCSharpDiagnosticAsync(TestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3333
}
3434

3535
[Fact]

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/StandardTextDiagnosticBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private static bool SeeTagIsCorrect(SyntaxNodeAnalysisContext context, XmlEmptyE
167167
}
168168

169169
INamedTypeSymbol expectedSymbol = semanticModel.GetDeclaredSymbol(constructorDeclarationSyntax.Parent, context.CancellationToken) as INamedTypeSymbol;
170-
return actualSymbol.OriginalDefinition == expectedSymbol;
170+
return Equals(actualSymbol.OriginalDefinition, expectedSymbol);
171171
}
172172

173173
private static bool SeeTagIsCorrect(SyntaxNodeAnalysisContext context, XElement classReferencePart, BaseMethodDeclarationSyntax constructorDeclarationSyntax)
@@ -193,7 +193,7 @@ private static bool SeeTagIsCorrect(SyntaxNodeAnalysisContext context, XElement
193193
}
194194

195195
INamedTypeSymbol expectedSymbol = semanticModel.GetDeclaredSymbol(constructorDeclarationSyntax.Parent, context.CancellationToken) as INamedTypeSymbol;
196-
return actualSymbol.OriginalDefinition == expectedSymbol;
196+
return Equals(actualSymbol.OriginalDefinition, expectedSymbol);
197197
}
198198

199199
private static bool TextPartsMatch(string firstText, string secondText, XmlTextSyntax firstTextPart, XmlTextSyntax secondTextPart)

0 commit comments

Comments
 (0)