Skip to content

Commit 2fe904f

Browse files
committed
Update SA1300 for static local functions
1 parent 551bba1 commit 2fe904f

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/NamingRules/SA1300CSharp7UnitTests.cs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp7.NamingRules
75
{
86
using System.Threading;
@@ -16,30 +14,14 @@ namespace StyleCop.Analyzers.Test.CSharp7.NamingRules
1614

1715
public partial class SA1300CSharp7UnitTests : SA1300UnitTests
1816
{
19-
[Fact]
20-
public async Task TestUpperCaseLocalFunctionAsync()
21-
{
22-
var testCode = @"public class TestClass
23-
{
24-
public void Method()
25-
{
26-
void LocalFunction()
27-
{
28-
}
29-
}
30-
}";
31-
32-
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
33-
}
34-
3517
[Fact]
3618
public async Task TestLowerCaseLocalFunctionAsync()
3719
{
3820
var testCode = @"public class TestClass
3921
{
4022
public void Method()
4123
{
42-
void localFunction()
24+
void {|#0:localFunction|}()
4325
{
4426
}
4527
}
@@ -54,7 +36,7 @@ void LocalFunction()
5436
}
5537
}";
5638

57-
DiagnosticResult expected = Diagnostic().WithArguments("localFunction").WithLocation(5, 14);
39+
DiagnosticResult expected = Diagnostic().WithArguments("localFunction").WithLocation(0);
5840
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
5941
}
6042

@@ -66,7 +48,7 @@ public async Task TestLowerCaseLocalFunctionWithConflictAsync()
6648
{
6749
public void Method()
6850
{
69-
void localFunction()
51+
void {|#0:localFunction|}()
7052
{
7153
}
7254
@@ -85,7 +67,7 @@ void LocalFunction1()
8567
}
8668
}";
8769

88-
DiagnosticResult expected = Diagnostic().WithArguments("localFunction").WithLocation(5, 14);
70+
DiagnosticResult expected = Diagnostic().WithArguments("localFunction").WithLocation(0);
8971
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
9072
}
9173
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/NamingRules/SA1300CSharp8UnitTests.cs

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

44
namespace StyleCop.Analyzers.Test.CSharp8.NamingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp7.NamingRules;
10+
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.NamingRules.SA1300ElementMustBeginWithUpperCaseLetter,
13+
StyleCop.Analyzers.NamingRules.RenameToUpperCaseCodeFixProvider>;
714

815
public partial class SA1300CSharp8UnitTests : SA1300CSharp7UnitTests
916
{
17+
[Fact]
18+
[WorkItem(3005, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3005")]
19+
public async Task TestLowerCaseStaticLocalFunctionAsync()
20+
{
21+
var testCode = @"public class TestClass
22+
{
23+
public void Method()
24+
{
25+
static void {|#0:localFunction|}()
26+
{
27+
}
28+
}
29+
}";
30+
var fixedCode = @"public class TestClass
31+
{
32+
public void Method()
33+
{
34+
static void LocalFunction()
35+
{
36+
}
37+
}
38+
}";
39+
40+
DiagnosticResult expected = Diagnostic().WithArguments("localFunction").WithLocation(0);
41+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
42+
}
1043
}
1144
}

documentation/SA1300.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ following types of elements should use an upper-case letter as the first letter
3333
* Events
3434
* Methods
3535
* Properties
36+
* Local functions (including static local functions)
3637

3738
In addition, any field which is public, internal, or marked with the const attribute should begin with an upper-case
3839
letter. Non-private readonly fields should also be named using an upper-case letter.

0 commit comments

Comments
 (0)