Skip to content

Commit b8aa3b6

Browse files
committed
Update to C# 9
1 parent d04c6cd commit b8aa3b6

6 files changed

Lines changed: 27 additions & 22 deletions

File tree

StyleCop.Analyzers/Directory.Build.props

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
</PropertyGroup>
1111

1212
<PropertyGroup>
13-
<LangVersion>8</LangVersion>
14-
<Features>strict</Features>
13+
<LangVersion>9</LangVersion>
14+
<WarningLevel>5</WarningLevel>
1515
</PropertyGroup>
1616

1717
<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
@@ -47,7 +47,12 @@
4747
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.46" PrivateAssets="all" />
4848
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.205" PrivateAssets="all" />
4949
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.0" PrivateAssets="all" />
50-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="3.7.0-6.20427.1" PrivateAssets="all" />
50+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="3.8.0-5.final" PrivateAssets="all" />
51+
</ItemGroup>
52+
53+
<!-- C# Compiler -->
54+
<ItemGroup>
55+
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.8.0-5.final" PrivateAssets="all" />
5156
</ItemGroup>
5257

5358
<!-- Public API -->

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1600CSharp9UnitTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace StyleCop.Analyzers.Test.CSharp9.DocumentationRules
88

99
public class SA1600CSharp9UnitTests : SA1600CSharp8UnitTests
1010
{
11-
protected override DiagnosticResult[] GetExpectedResultTestRegressionMethodGlobalNamespace(string code, int column)
11+
protected override DiagnosticResult[] GetExpectedResultTestRegressionMethodGlobalNamespace(string code)
1212
{
13-
if (code == "public void TestMember() { }" && column == 13)
13+
if (code == "public void {|#0:TestMember|}() { }")
1414
{
1515
return new[]
1616
{
@@ -20,12 +20,12 @@ protected override DiagnosticResult[] GetExpectedResultTestRegressionMethodGloba
2020
// /0/Test0.cs(4,1): error CS0106: The modifier 'public' is not valid for this item
2121
DiagnosticResult.CompilerError("CS0106").WithSpan(4, 1, 4, 7).WithArguments("public"),
2222

23-
// /0/Test0.cs(4,1): error CS8652: The feature 'top-level statements' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
24-
DiagnosticResult.CompilerError("CS8652").WithSpan(4, 1, 4, 29).WithArguments("top-level statements"),
23+
// /0/Test0.cs(4,1): error CS8320: Feature 'top-level statements' is not available in C# 7.2. Please use language version 9.0 or greater.
24+
DiagnosticResult.CompilerError("CS8320").WithSpan(4, 1, 4, 29).WithArguments("top-level statements", "9.0"),
2525
};
2626
}
2727

28-
return base.GetExpectedResultTestRegressionMethodGlobalNamespace(code, column);
28+
return base.GetExpectedResultTestRegressionMethodGlobalNamespace(code);
2929
}
3030
}
3131
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/StyleCop.Analyzers.Test.CSharp9.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.8.0-2.20414.4" />
20+
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.8.0-5.final" />
2121
<PackageReference Include="xunit" Version="2.4.1" />
2222
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
2323
</ItemGroup>

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ public class SA1600UnitTests
2121
protected virtual LanguageVersion LanguageVersion => LanguageVersion.CSharp6;
2222

2323
[Theory]
24-
[InlineData("public string TestMember;", 15)]
25-
[InlineData("public string TestMember { get; set; }", 15)]
26-
[InlineData("public void TestMember() { }", 13)]
27-
[InlineData("public string this[int a] { get { return \"a\"; } set { } }", 15)]
28-
[InlineData("public event EventHandler TestMember { add { } remove { } }", 27)]
29-
public async Task TestRegressionMethodGlobalNamespaceAsync(string code, int column)
24+
[InlineData("public string {|#0:TestMember|};")]
25+
[InlineData("public string {|#0:TestMember|} { get; set; }")]
26+
[InlineData("public void {|#0:TestMember|}() { }")]
27+
[InlineData("public string {|#0:this|}[int a] { get { return \"a\"; } set { } }")]
28+
[InlineData("public event EventHandler {|#0:TestMember|} { add { } remove { } }")]
29+
public async Task TestRegressionMethodGlobalNamespaceAsync(string code)
3030
{
3131
// This test is a regression test for https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1416
3232
var testCode = $@"
3333
using System;
3434
3535
{code}";
3636

37-
var expected = this.GetExpectedResultTestRegressionMethodGlobalNamespace(code, column);
37+
var expected = this.GetExpectedResultTestRegressionMethodGlobalNamespace(code);
3838
await VerifyCSharpDiagnosticAsync(this.LanguageVersion, testCode, expected, CancellationToken.None).ConfigureAwait(false);
3939
}
4040

@@ -1384,12 +1384,12 @@ public class OuterClass
13841384
await VerifyCSharpDiagnosticAsync(this.LanguageVersion, string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
13851385
}
13861386

1387-
protected virtual DiagnosticResult[] GetExpectedResultTestRegressionMethodGlobalNamespace(string code, int column)
1387+
protected virtual DiagnosticResult[] GetExpectedResultTestRegressionMethodGlobalNamespace(string code)
13881388
{
13891389
return new[]
13901390
{
1391-
DiagnosticResult.CompilerError("CS0116").WithMessage("A namespace cannot directly contain members such as fields or methods").WithLocation(4, column),
1392-
Diagnostic().WithLocation(4, column),
1391+
DiagnosticResult.CompilerError("CS0116").WithMessage("A namespace cannot directly contain members such as fields or methods").WithLocation(0),
1392+
Diagnostic().WithLocation(0),
13931393
};
13941394
}
13951395

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1501UnitTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,15 +818,15 @@ public void Bar(int i)
818818
Diagnostic().WithLocation(21, 26),
819819
Diagnostic().WithLocation(21, 52),
820820
Diagnostic().WithLocation(21, 78),
821-
Diagnostic().WithLocation(23, 22).WithSeverity(DiagnosticSeverity.Hidden),
821+
Diagnostic().WithLocation(23, 22),
822822
Diagnostic().WithLocation(23, 35),
823823
Diagnostic().WithLocation(24, 18),
824824
Diagnostic().WithLocation(24, 57),
825825
},
826826
FixedCode = incrementalFixedCode,
827827
RemainingDiagnostics =
828828
{
829-
Diagnostic().WithLocation(50, 22).WithSeverity(DiagnosticSeverity.Hidden),
829+
Diagnostic().WithLocation(50, 22),
830830
},
831831
BatchFixedCode = batchFixedCode,
832832
DisabledDiagnostics =

StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<ItemGroup>
2020
<PackageReference Include="Microsoft.CodeAnalysis" Version="1.3.2" />
21-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.0.1-beta1.20478.1" />
21+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.0.1-beta1.20521.1" />
2222
<PackageReference Include="Microsoft.VisualStudio.Composition" Version="16.1.8" />
2323
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
2424
<PackageReference Include="xunit" Version="2.4.1" />

0 commit comments

Comments
 (0)