Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
var token = root.FindToken(diagnostic.Location.SourceSpan.Start);
var tokenText = token.ValueText.TrimStart('_');
if (tokenText == string.Empty)
{
// Skip this one, since we can't create a new identifier from this
continue;
}

var baseName = char.ToUpper(tokenText[0]) + tokenText.Substring(1);
var newName = baseName;
var memberSyntax = RenameHelper.GetParentDeclaration(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,5 +982,30 @@ public async Task TestUnderscoreExclusionAsync()

await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

[Theory]
[InlineData("_")]
[InlineData("__")]
[WorkItem(3636, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3636")]
public async Task TestUnderscoreMethodAsync(string name)
{
var testCode = $@"
public class TestClass
{{
public void [|{name}|]()
{{
}}
}}";

var fixedCode = $@"
public class TestClass
{{
public void [|{name}|]()
{{
}}
}}";

await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}