Skip to content

Commit

Permalink
Make the ':severity' suffix in editorconfig code style value optional
Browse files Browse the repository at this point in the history
Contributes towards dotnet#44201

- All code style option editorconfig entries can now be specified as `option_name = option_value` without `:severity` suffix
- `Configure code style option` code fix will no longer add add `:severity` suffix for new entries. For fix that changes existing entries which have `:severity` suffix, it will retain the existing severity suffix. Note that `Configure severity` code fix was already switched to use `dotnet_diagnostic.RuleID.severity` entries for code style diagnostics in dotnet#47052.

Once we have the editorconfig UX to change code style option value and severity, we can safely deprecate the `:severity` suffix in option value syntax. All our UI gestures will use the `option_name = option_value` syntax for code style value changes and `dotnet_diagnostic.RuleID.severity = severity` syntax for severity changes and users do not need to deal with these manually editing or understanind these different syntaxes or mapping rule IDs to option names and vice versa for code styles.
  • Loading branch information
mavasani committed Oct 14, 2020
1 parent fd27fc7 commit babde04
Show file tree
Hide file tree
Showing 17 changed files with 878 additions and 663 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Customer()
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{cs,vb}]
# IDE0017: Simplify object initialization
dotnet_style_object_initializer = true:suggestion
dotnet_style_object_initializer = true
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -247,7 +247,7 @@ public Customer()
[*.{cs,vb}]
# IDE0017: Simplify object initialization
dotnet_style_object_initializer = true:suggestion
dotnet_style_object_initializer = true
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -359,6 +359,7 @@ public Customer()
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.cs]
dotnet_style_object_initializerr = false:suggestion
dotnet_style_object_initializerr = false
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -392,9 +393,10 @@ public Customer()
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.cs]
dotnet_style_object_initializerr = false:suggestion
dotnet_style_object_initializerr = false
# IDE0017: Simplify object initialization
dotnet_style_object_initializer = true:suggestion
dotnet_style_object_initializer = true
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -471,7 +473,7 @@ public Customer()
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{cs,vb}]
# IDE0017: Simplify object initialization
dotnet_style_object_initializer = false:suggestion
dotnet_style_object_initializer = false
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -551,6 +553,78 @@ public Customer()
await TestInRegularAndScriptAsync(input, expected, CodeActionIndex);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)]
public async Task ConfigureEditorconfig_RuleExists_False_NoSeveritySuffix()
{
var input = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
class Program1
{
static void Main()
{
// dotnet_style_object_initializer = true
var obj = new Customer() { _age = 21 };
// dotnet_style_object_initializer = false
Customer obj2 = [|new Customer()|];
obj2._age = 21;
}
internal class Customer
{
public int _age;
public Customer()
{
}
}
}
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.cs]
dotnet_style_object_initializer = true
</AnalyzerConfigDocument>
</Project>
</Workspace>";

var expected = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
class Program1
{
static void Main()
{
// dotnet_style_object_initializer = true
var obj = new Customer() { _age = 21 };
// dotnet_style_object_initializer = false
Customer obj2 = new Customer();
obj2._age = 21;
}
internal class Customer
{
public int _age;
public Customer()
{
}
}
}
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.cs]
dotnet_style_object_initializer = false
</AnalyzerConfigDocument>
</Project>
</Workspace>";

await TestInRegularAndScriptAsync(input, expected, CodeActionIndex);
}

[ConditionalFact(typeof(IsEnglishLocal)), Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)]
public async Task ConfigureEditorconfig_RuleExists_DotnetDiagnosticEntry()
{
Expand Down Expand Up @@ -618,7 +692,7 @@ public Customer()
dotnet_diagnostic.IDE0017.severity = warning
# IDE0017: Simplify object initialization
dotnet_style_object_initializer = false:warning
dotnet_style_object_initializer = false
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -769,7 +843,7 @@ public Customer()
[*.{cs,vb}]
# IDE0017: Simplify object initialization
dotnet_style_object_initializer = false:suggestion
dotnet_style_object_initializer = false
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -916,7 +990,7 @@ public Customer()
dotnet_style_object_initializerr = false:suggestion
# IDE0017: Simplify object initialization
dotnet_style_object_initializer = false:suggestion
dotnet_style_object_initializer = false
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void Main()
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.cs]
# IDE0059: Unnecessary assignment of a value
csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion
csharp_style_unused_value_assignment_preference = unused_local_variable
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -186,7 +186,7 @@ static void Main()
dotnet_diagnostic.IDE0059.severity = warning ; Comment2
# IDE0059: Unnecessary assignment of a value
csharp_style_unused_value_assignment_preference = unused_local_variable:warning
csharp_style_unused_value_assignment_preference = unused_local_variable
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -289,7 +289,7 @@ static void Main()
[*.cs]
# IDE0059: Unnecessary assignment of a value
csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion
csharp_style_unused_value_assignment_preference = unused_local_variable
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -388,7 +388,7 @@ static void Main()
csharp_style_unused_value_assignment_preferencer = discard_variable:suggestion
# IDE0059: Unnecessary assignment of a value
csharp_style_unused_value_assignment_preference = unused_local_variable:suggestion
csharp_style_unused_value_assignment_preference = unused_local_variable
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -441,7 +441,7 @@ static void Main()
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.cs]
# IDE0059: Unnecessary assignment of a value
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_assignment_preference = discard_variable
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -497,6 +497,54 @@ static void Main()
await TestInRegularAndScriptAsync(input, expected, CodeActionIndex);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)]
public async Task ConfigureEditorconfig_RuleExists_DiscardVariable_WithoutSeveritySuffix()
{
var input = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
class Program1
{
static void Main()
{
// csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable }
[|var obj = new Program1();|]
obj = null;
var obj2 = obj;
}
}
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.cs]
csharp_style_unused_value_assignment_preference = unused_local_variable
</AnalyzerConfigDocument>
</Project>
</Workspace>";

var expected = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
class Program1
{
static void Main()
{
// csharp_style_unused_value_assignment_preference = { discard_variable, unused_local_variable }
var obj = new Program1();
obj = null;
var obj2 = obj;
}
}
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.cs]
csharp_style_unused_value_assignment_preference = discard_variable
</AnalyzerConfigDocument>
</Project>
</Workspace>";

await TestInRegularAndScriptAsync(input, expected, CodeActionIndex);
}

[ConditionalFact(typeof(IsEnglishLocal)), Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)]
public async Task ConfigureEditorconfig_InvalidHeader_DiscardVariable()
{
Expand Down Expand Up @@ -542,7 +590,7 @@ static void Main()
[*.cs]
# IDE0059: Unnecessary assignment of a value
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_assignment_preference = discard_variable
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down Expand Up @@ -641,7 +689,7 @@ static void Main()
csharp_style_unused_value_assignment_preference_error = discard_variable:suggestion
# IDE0059: Unnecessary assignment of a value
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_assignment_preference = discard_variable
</AnalyzerConfigDocument>
</Project>
</Workspace>";
Expand Down
Loading

0 comments on commit babde04

Please sign in to comment.