Skip to content

Commit e8f8552

Browse files
committed
Fix SA1300 implicit reliance on default line endings
1 parent ff6daeb commit e8f8552

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/NamingRules/RenameToUpperCaseCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Task<Document> RenameNamespace(CancellationToken cancellationToken)
7676
{
7777
IdentifierNameSyntax identifierSyntax = (IdentifierNameSyntax)token.Parent;
7878

79-
var newIdentifierSyntax = identifierSyntax.WithIdentifier(SyntaxFactory.Identifier(newName));
79+
var newIdentifierSyntax = identifierSyntax.WithIdentifier(SyntaxFactory.Identifier(newName)).WithTriviaFrom(identifierSyntax);
8080

8181
var newRoot = root.ReplaceNode(identifierSyntax, newIdentifierSyntax);
8282
return Task.FromResult(context.Document.WithSyntaxRoot(newRoot));

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1300UnitTests.cs

Lines changed: 8 additions & 8 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.NamingRules
75
{
86
using System.Threading;
@@ -28,20 +26,22 @@ public async Task TestUpperCaseNamespaceAsync()
2826
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
2927
}
3028

31-
[Fact]
32-
public async Task TestLowerCaseNamespaceAsync()
29+
[Theory]
30+
[InlineData("\n")]
31+
[InlineData("\r\n")]
32+
public async Task TestLowerCaseNamespaceAsync(string lineEnding)
3333
{
34-
var testCode = @"namespace test
34+
var testCode = @"namespace {|#0:test|}
3535
{
3636
37-
}";
37+
}".ReplaceLineEndings(lineEnding);
3838

3939
var fixedCode = @"namespace Test
4040
{
4141
42-
}";
42+
}".ReplaceLineEndings(lineEnding);
4343

44-
DiagnosticResult expected = Diagnostic().WithArguments("test").WithLocation(1, 11);
44+
DiagnosticResult expected = Diagnostic().WithArguments("test").WithLocation(0);
4545
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
4646
}
4747

0 commit comments

Comments
 (0)