提交 64d702c0 编写于 作者: M Manish Vasani

Handle invalid dotnet_diagnostic entry without ID part in configuration code fix

Fixes #45446
上级 600d79d1
......@@ -193,6 +193,40 @@ public async Task ConfigureEditorconfig_InvalidRule_None()
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{vb,cs}]
dotnet_diagnostic.XYZ1111.severity = none
# XYZ0001: Title
dotnet_diagnostic.XYZ0001.severity = none
</AnalyzerConfigDocument>
</Project>
</Workspace>";
await TestInRegularAndScriptAsync(input, expected, CodeActionIndex);
}
[ConditionalFact(typeof(IsEnglishLocal)), Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)]
[WorkItem(45446, "https://github.com/dotnet/roslyn/issues/45446")]
public async Task ConfigureEditorconfig_MissingRule_None()
{
var input = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
[|class Program1 { }|]
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{vb,cs}]
dotnet_diagnostic.severity = none
</AnalyzerConfigDocument>
</Project>
</Workspace>";
var expected = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
[|class Program1 { }|]
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{vb,cs}]
dotnet_diagnostic.severity = none
# XYZ0001: Title
dotnet_diagnostic.XYZ0001.severity = none
</AnalyzerConfigDocument>
......
......@@ -488,10 +488,13 @@ private async Task<Solution> ConfigureAsync()
key.EndsWith(SeveritySuffix, StringComparison.Ordinal))
{
var diagIdLength = key.Length - (DiagnosticOptionPrefix.Length + SeveritySuffix.Length);
var diagId = key.Substring(DiagnosticOptionPrefix.Length, diagIdLength);
if (string.Equals(diagId, _diagnostic.Id, StringComparison.OrdinalIgnoreCase))
if (diagIdLength > 0)
{
textChange = new TextChange(curLine.Span, $"{key} = {_newSeverity}{commentValue}");
var diagId = key.Substring(DiagnosticOptionPrefix.Length, diagIdLength);
if (string.Equals(diagId, _diagnostic.Id, StringComparison.OrdinalIgnoreCase))
{
textChange = new TextChange(curLine.Span, $"{key} = {_newSeverity}{commentValue}");
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册