Skip to content

Commit 3800377

Browse files
committed
Merge branch 'master' into issue2575
# Conflicts: # azure-pipelines.yml
2 parents 80804ab + be49652 commit 3800377

File tree

11 files changed

+507
-75
lines changed

11 files changed

+507
-75
lines changed

.nuget/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Codecov" version="1.9.0" />
3+
<package id="CodecovUploader" version="0.7.1" />
44
<package id="OpenCover" version="4.6.519" />
5-
<package id="ReportGenerator" version="2.3.5.0" targetFramework="net452" />
5+
<package id="ReportGenerator" version="5.2.0" />
66
<package id="xunit.runner.console" version="2.4.1" />
77
</packages>

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/LayoutRules/SA1513CSharp12UnitTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,34 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp12.LayoutRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp11.LayoutRules;
10+
using Xunit;
11+
12+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
13+
StyleCop.Analyzers.LayoutRules.SA1513ClosingBraceMustBeFollowedByBlankLine,
14+
StyleCop.Analyzers.LayoutRules.SA1513CodeFixProvider>;
715

816
public partial class SA1513CSharp12UnitTests : SA1513CSharp11UnitTests
917
{
18+
[Fact]
19+
[WorkItem(3720, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3720")]
20+
public async Task TestObjectInitializerInCollectionExpressionAsync()
21+
{
22+
var testCode = @"
23+
public class Foo
24+
{
25+
public Foo[] TestMethod() =>
26+
[
27+
new Foo
28+
{
29+
}
30+
];
31+
}";
32+
33+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, testCode, CancellationToken.None).ConfigureAwait(false);
34+
}
1035
}
1136
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/ReadabilityRules/SA1118CSharp12UnitTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,41 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp12.ReadabilityRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp11.ReadabilityRules;
10+
using Xunit;
11+
12+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopDiagnosticVerifier<
13+
StyleCop.Analyzers.ReadabilityRules.SA1118ParameterMustNotSpanMultipleLines>;
714

815
public partial class SA1118CSharp12UnitTests : SA1118CSharp11UnitTests
916
{
17+
[Fact]
18+
[WorkItem(3732, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3732")]
19+
public async Task TestCollectionExpressionAsync()
20+
{
21+
var testCode = @"
22+
class Foo
23+
{
24+
public void TestMethod()
25+
{
26+
AnotherMethod(
27+
42,
28+
[
29+
1,
30+
2,
31+
3
32+
]);
33+
}
34+
35+
public void AnotherMethod(int x, int[] y)
36+
{
37+
}
38+
}";
39+
40+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
41+
}
1042
}
1143
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1010CSharp12UnitTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,47 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp11.SpacingRules;
10+
using Xunit;
11+
12+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
13+
StyleCop.Analyzers.SpacingRules.SA1010OpeningSquareBracketsMustBeSpacedCorrectly,
14+
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
715

816
public partial class SA1010CSharp12UnitTests : SA1010CSharp11UnitTests
917
{
18+
[Fact]
19+
[WorkItem(3687, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3687")]
20+
public async Task TestCollectionExpressionAsync()
21+
{
22+
var testCode = $@"
23+
using System.Collections.Generic;
24+
25+
namespace TestNamespace
26+
{{
27+
public class TestClass
28+
{{
29+
protected static readonly int[] DefaultMetadataPaths = [1, 2];
30+
31+
public void TestMethod(List<int> x, int y)
32+
{{
33+
List<int> foo = [];
34+
foo = [42];
35+
foo = [..x, y];
36+
Bar([1 ,2, 3]);
37+
}}
38+
39+
public void Bar(int[] x)
40+
{{
41+
}}
42+
}}
43+
}}
44+
";
45+
46+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
47+
}
1048
}
1149
}

StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1513ClosingBraceMustBeFollowedByBlankLine.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ private void AnalyzeCloseBrace(SyntaxToken token)
272272
return;
273273
}
274274

275+
if (nextToken.IsKind(SyntaxKind.CloseBracketToken))
276+
{
277+
// the close brace is for example in an object initializer at the end of a collection expression.
278+
return;
279+
}
280+
275281
if (nextToken.IsKind(SyntaxKind.AddKeyword)
276282
|| nextToken.IsKind(SyntaxKind.RemoveKeyword)
277283
|| nextToken.IsKind(SyntaxKind.GetKeyword)

StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,6 @@ internal static class SyntaxKindEx
6969
public const SyntaxKind RecordDeclaration = (SyntaxKind)9063;
7070
public const SyntaxKind FunctionPointerUnmanagedCallingConventionList = (SyntaxKind)9066;
7171
public const SyntaxKind RecordStructDeclaration = (SyntaxKind)9068;
72+
public const SyntaxKind CollectionExpression = (SyntaxKind)9076;
7273
}
7374
}

StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1118ParameterMustNotSpanMultipleLines.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ internal class SA1118ParameterMustNotSpanMultipleLines : DiagnosticAnalyzer
8787
SyntaxKind.ImplicitArrayCreationExpression,
8888
SyntaxKindEx.WithExpression,
8989
SyntaxKindEx.ImplicitObjectCreationExpression,
90+
SyntaxKindEx.CollectionExpression,
9091
};
9192

9293
/// <inheritdoc/>

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1010OpeningSquareBracketsMustBeSpacedCorrectly.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private static void HandleOpenBracketToken(SyntaxTreeAnalysisContext context, Sy
100100
}
101101

102102
if (!firstInLine && precededBySpace && !ignorePrecedingSpaceProblem &&
103-
!IsPartOfIndexInitializer(token) && !IsPartOfListPattern(token))
103+
!IsPartOfIndexInitializer(token) && !IsPartOfListPattern(token) && !IsPartOfCollectionExpression(token))
104104
{
105105
// Opening square bracket should {not be preceded} by a space.
106106
context.ReportDiagnostic(Diagnostic.Create(DescriptorNotPreceded, token.GetLocation(), TokenSpacingProperties.RemovePreceding));
@@ -128,5 +128,10 @@ private static bool IsPartOfListPattern(SyntaxToken token)
128128
{
129129
return token.Parent.IsKind(SyntaxKindEx.ListPattern);
130130
}
131+
132+
private static bool IsPartOfCollectionExpression(SyntaxToken token)
133+
{
134+
return token.Parent.IsKind(SyntaxKindEx.CollectionExpression);
135+
}
131136
}
132137
}

azure-pipelines.yml

Lines changed: 8 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,16 @@
1-
pool:
1+
pool:
22
name: Azure Pipelines
33
vmImage: windows-latest
44
demands:
55
- msbuild
66
- visualstudio
77
- vstest
88

9-
jobs:
10-
- job: Build
11-
variables:
12-
BuildSolution: StyleCopAnalyzers.sln
13-
BuildPlatform: Any CPU
14-
strategy:
15-
matrix:
16-
Debug:
17-
BuildConfiguration: Debug
18-
_debugArg: '-Debug'
19-
Release:
20-
BuildConfiguration: Release
21-
_debugArg: ''
22-
timeoutInMinutes: 90
23-
steps:
24-
- powershell: .\init.ps1 -NoRestore
25-
displayName: Install .NET Core SDK
9+
stages:
10+
- template: build/build-and-test.yml
11+
parameters:
12+
BuildConfiguration: Debug
2613

27-
- task: NuGetToolInstaller@0
28-
displayName: 'Use NuGet 5.3.1'
29-
inputs:
30-
versionSpec: 5.3.1
31-
32-
- task: NuGetCommand@2
33-
displayName: 'NuGet restore'
34-
inputs:
35-
restoreSolution: '$(BuildSolution)'
36-
feedsToUse: 'config'
37-
nugetConfigPath: 'NuGet.config'
38-
39-
- task: VSBuild@1
40-
displayName: 'Build solution StyleCopAnalyzers.sln'
41-
inputs:
42-
solution: '$(BuildSolution)'
43-
platform: '$(BuildPlatform)'
44-
configuration: '$(BuildConfiguration)'
45-
msbuildArgs: '/bl:$(Build.SourcesDirectory)/msbuild.binlog'
46-
47-
- task: PowerShell@2
48-
displayName: Run Tests
49-
timeoutInMinutes: 80
50-
inputs:
51-
workingDirectory: '$(Build.SourcesDirectory)/build'
52-
filePath: build/opencover-report.ps1
53-
arguments: '$(_debugArg) -NoBuild -NoReport -Azure'
54-
55-
- task: PublishTestResults@2
56-
displayName: Publish test results
57-
condition: always()
58-
inputs:
59-
testResultsFormat: xUnit
60-
testResultsFiles: 'build/*.xml'
61-
mergeTestResults: true
62-
testRunTitle: '$(BuildConfiguration)'
63-
64-
- task: PowerShell@2
65-
displayName: Upload coverage reports to codecov.io
66-
condition: eq(variables['BuildConfiguration'], 'Debug')
67-
inputs:
68-
workingDirectory: '$(Build.SourcesDirectory)/build'
69-
targetType: inline
70-
script: |
71-
$packageConfig = [xml](Get-Content ..\.nuget\packages.config)
72-
$codecov_version = $packageConfig.SelectSingleNode('/packages/package[@id="Codecov"]').version
73-
$codecov = "..\packages\Codecov.$codecov_version\tools\codecov.exe"
74-
&$codecov -f '..\build\OpenCover.Reports\OpenCover.StyleCopAnalyzers.xml' --required
75-
76-
- task: PublishBuildArtifacts@1
77-
displayName: Publish build logs
78-
inputs:
79-
pathtoPublish: msbuild.binlog
80-
condition: failed()
14+
- template: build/build-and-test.yml
15+
parameters:
16+
BuildConfiguration: Release

0 commit comments

Comments
 (0)