未验证 提交 ee8b7388 编写于 作者: M msftbot[bot] 提交者: GitHub

Merge pull request #40048 from dotnet/merges/master-to-master-vs-deps

Merge master to master-vs-deps
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeFixes.Configuration.ConfigureSeverity;
using Microsoft.CodeAnalysis.CSharp.UseInferredMemberName;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics.Configuration.ConfigureSeverity
{
public abstract partial class MultipleCodeStyleOptionBasedSeverityConfigurationTests : AbstractSuppressionDiagnosticTest
{
protected override TestWorkspace CreateWorkspaceFromFile(string initialMarkup, TestParameters parameters)
=> TestWorkspace.CreateCSharp(initialMarkup, parameters.parseOptions, parameters.compilationOptions);
protected override string GetLanguage() => LanguageNames.CSharp;
protected override ParseOptions GetScriptOptions() => Options.Script;
internal override Tuple<DiagnosticAnalyzer, IConfigurationFixProvider> CreateDiagnosticProviderAndFixer(Workspace workspace)
{
return new Tuple<DiagnosticAnalyzer, IConfigurationFixProvider>(
new CSharpUseInferredMemberNameDiagnosticAnalyzer(), new ConfigureSeverityLevelCodeFixProvider());
}
public class ErrorConfigurationTests : MultipleCodeStyleOptionBasedSeverityConfigurationTests
{
protected override int CodeActionIndex => 4;
[WorkItem(39664, "https://github.com/dotnet/roslyn/issues/39664")]
[ConditionalFact(typeof(IsEnglishLocal)), Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)]
public async Task ConfigureEditorconfig_Empty_Error()
{
var input = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
using System;
namespace ConsoleApp5
{
class Foo
{
public string RuleName = ""test"";
}
class Bar
{
static void Main(string[] args)
{
var foo = new Foo();
var bar = new { [|RuleName|] = foo.RuleName };
Console.WriteLine(bar.RuleName);
}
}
}
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig""></AnalyzerConfigDocument>
</Project>
</Workspace>";
var expected = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
using System;
namespace ConsoleApp5
{
class Foo
{
public string RuleName = ""test"";
}
class Bar
{
static void Main(string[] args)
{
var foo = new Foo();
var bar = new { RuleName = foo.RuleName };
Console.WriteLine(bar.RuleName);
}
}
}
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{cs,vb}]
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_anonymous_type_member_names = true:error
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_tuple_names = true:error
</AnalyzerConfigDocument>
</Project>
</Workspace>";
await TestInRegularAndScriptAsync(input, expected, CodeActionIndex);
}
[WorkItem(39664, "https://github.com/dotnet/roslyn/issues/39664")]
[ConditionalFact(typeof(IsEnglishLocal)), Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)]
public async Task ConfigureEditorconfig_BothRulesExist_Error()
{
var input = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
using System;
namespace ConsoleApp5
{
class Foo
{
public string RuleName = ""test"";
}
class Bar
{
static void Main(string[] args)
{
var foo = new Foo();
var bar = new { [|RuleName|] = foo.RuleName };
Console.WriteLine(bar.RuleName);
}
}
}
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{cs,vb}]
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_tuple_names = true:suggestion
</AnalyzerConfigDocument>
</Project>
</Workspace>";
var expected = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
using System;
namespace ConsoleApp5
{
class Foo
{
public string RuleName = ""test"";
}
class Bar
{
static void Main(string[] args)
{
var foo = new Foo();
var bar = new { RuleName = foo.RuleName };
Console.WriteLine(bar.RuleName);
}
}
}
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{cs,vb}]
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_anonymous_type_member_names = true:error
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_tuple_names = true:error
</AnalyzerConfigDocument>
</Project>
</Workspace>";
await TestInRegularAndScriptAsync(input, expected, CodeActionIndex);
}
[WorkItem(39664, "https://github.com/dotnet/roslyn/issues/39664")]
[ConditionalFact(typeof(IsEnglishLocal)), Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)]
public async Task ConfigureEditorconfig_OneRuleExists_Error()
{
var input = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
using System;
namespace ConsoleApp5
{
class Foo
{
public string RuleName = ""test"";
}
class Bar
{
static void Main(string[] args)
{
var foo = new Foo();
var bar = new { [|RuleName|] = foo.RuleName };
Console.WriteLine(bar.RuleName);
}
}
}
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{cs,vb}]
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
</AnalyzerConfigDocument>
</Project>
</Workspace>";
var expected = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
using System;
namespace ConsoleApp5
{
class Foo
{
public string RuleName = ""test"";
}
class Bar
{
static void Main(string[] args)
{
var foo = new Foo();
var bar = new { RuleName = foo.RuleName };
Console.WriteLine(bar.RuleName);
}
}
}
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{cs,vb}]
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_anonymous_type_member_names = true:error
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_tuple_names = true:error
</AnalyzerConfigDocument>
</Project>
</Workspace>";
await TestInRegularAndScriptAsync(input, expected, CodeActionIndex);
}
}
}
}
......@@ -255,7 +255,7 @@ public void CSharp_VerifyIDEDiagnosticSeveritiesAreConfigurable()
dotnet_diagnostic.IDE0036.severity = %value%
# IDE0037
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_diagnostic.IDE0037.severity = %value%
# IDE0039
csharp_style_pattern_local_over_anonymous_function = true:suggestion
......@@ -419,7 +419,7 @@ public void VisualBasic_VerifyIDEDiagnosticSeveritiesAreConfigurable()
dotnet_diagnostic.IDE0036.severity = %value%
# IDE0037
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_diagnostic.IDE0037.severity = %value%
# IDE0040
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
......@@ -721,6 +721,9 @@ public void CSharp_VerifyIDECodeStyleOptionsAreConfigurable()
# IDE0037, PreferInferredTupleNames
dotnet_style_prefer_inferred_tuple_names = true:suggestion
# IDE0037, PreferInferredAnonymousTypeMemberNames
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
# IDE0039, PreferLocalOverAnonymousFunction
csharp_style_pattern_local_over_anonymous_function = true:suggestion
......@@ -915,6 +918,9 @@ public void VisualBasic_VerifyIDECodeStyleOptionsAreConfigurable()
# IDE0037, PreferInferredTupleNames
dotnet_style_prefer_inferred_tuple_names = true:suggestion
# IDE0037, PreferInferredAnonymousTypeMemberNames
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
# IDE0040, RequireAccessibilityModifiers
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.CodeFixes.Configuration.ConfigureSeverity
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports Microsoft.CodeAnalysis.VisualBasic.UseInferredMemberName
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Diagnostics.Configuration.ConfigureCodeStyle
Partial Public MustInherit Class MultipleCodeStyleOptionBasedConfigureSeverityTests
Inherits AbstractSuppressionDiagnosticTest
Protected Overrides Function CreateWorkspaceFromFile(initialMarkup As String, parameters As TestParameters) As TestWorkspace
Return TestWorkspace.CreateVisualBasic(
initialMarkup,
parameters.parseOptions,
If(parameters.compilationOptions, New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary)))
End Function
Protected Overrides Function GetLanguage() As String
Return LanguageNames.VisualBasic
End Function
Protected Overrides Function GetScriptOptions() As ParseOptions
Return TestOptions.Script
End Function
Friend Overrides Function CreateDiagnosticProviderAndFixer(ByVal workspace As Workspace) As Tuple(Of DiagnosticAnalyzer, IConfigurationFixProvider)
Return New Tuple(Of DiagnosticAnalyzer, IConfigurationFixProvider)(New VisualBasicUseInferredMemberNameDiagnosticAnalyzer(), New ConfigureSeverityLevelCodeFixProvider())
End Function
End Class
Public Class ErrorConfigurationTests
Inherits MultipleCodeStyleOptionBasedConfigureSeverityTests
Protected Overrides ReadOnly Property CodeActionIndex As Integer
Get
Return 4
End Get
End Property
<WorkItem(39664, "https://github.com/dotnet/roslyn/issues/39664")>
<ConditionalFact(GetType(IsEnglishLocal)), Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)>
Public Async Function ConfigureEditorconfig_Empty_Error() As Task
Dim input = "
<Workspace>
<Project Language=""Visual Basic"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.vb"">
Class C
Sub M()
Dim a As Integer = 1
Dim t = ([||]a:= a, 2)
End Sub
End Class
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig""></AnalyzerConfigDocument>
</Project>
</Workspace>"
Dim expected = "
<Workspace>
<Project Language=""Visual Basic"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.vb"">
Class C
Sub M()
Dim a As Integer = 1
Dim t = (a:= a, 2)
End Sub
End Class
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{cs,vb}]
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_anonymous_type_member_names = true:error
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_tuple_names = true:error
</AnalyzerConfigDocument>
</Project>
</Workspace>"
Await TestInRegularAndScriptAsync(input, expected, CodeActionIndex)
End Function
<WorkItem(39664, "https://github.com/dotnet/roslyn/issues/39664")>
<ConditionalFact(GetType(IsEnglishLocal)), Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)>
Public Async Function ConfigureEditorconfig_BothRulesExist_Error() As Task
Dim input = "
<Workspace>
<Project Language=""Visual Basic"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.vb"">
Class C
Sub M()
Dim a As Integer = 1
Dim t = ([||]a:= a, 2)
End Sub
End Class
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{cs,vb}]
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_tuple_names = true:suggestion
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
</AnalyzerConfigDocument>
</Project>
</Workspace>"
Dim expected = "
<Workspace>
<Project Language=""Visual Basic"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.vb"">
Class C
Sub M()
Dim a As Integer = 1
Dim t = (a:= a, 2)
End Sub
End Class
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{cs,vb}]
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_tuple_names = true:error
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_anonymous_type_member_names = true:error
</AnalyzerConfigDocument>
</Project>
</Workspace>"
Await TestInRegularAndScriptAsync(input, expected, CodeActionIndex)
End Function
<WorkItem(39664, "https://github.com/dotnet/roslyn/issues/39664")>
<ConditionalFact(GetType(IsEnglishLocal)), Trait(Traits.Feature, Traits.Features.CodeActionsConfiguration)>
Public Async Function ConfigureEditorconfig_OneRuleExists_Error() As Task
Dim input = "
<Workspace>
<Project Language=""Visual Basic"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.vb"">
Class C
Sub M()
Dim a As Integer = 1
Dim t = ([||]a:= a, 2)
End Sub
End Class
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{cs,vb}]
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
</AnalyzerConfigDocument>
</Project>
</Workspace>"
Dim expected = "
<Workspace>
<Project Language=""Visual Basic"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.vb"">
Class C
Sub M()
Dim a As Integer = 1
Dim t = (a:= a, 2)
End Sub
End Class
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.{cs,vb}]
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_anonymous_type_member_names = true:error
# IDE0037: Use inferred member name
dotnet_style_prefer_inferred_tuple_names = true:error
</AnalyzerConfigDocument>
</Project>
</Workspace>"
Await TestInRegularAndScriptAsync(input, expected, CodeActionIndex)
End Function
End Class
End Namespace
......@@ -308,7 +308,7 @@ private AnalyzerConfigDocument FindOrGenerateEditorConfig()
try
{
foreach (var option in options)
foreach (var option in options.OrderBy(option => option.Name))
{
var editorConfigLocation = option.StorageLocations.OfType<IEditorConfigStorageLocation2>().FirstOrDefault();
if (editorConfigLocation != null)
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Options;
......@@ -12,7 +13,7 @@ internal abstract class AbstractUseInferredMemberNameDiagnosticAnalyzer : Abstra
public AbstractUseInferredMemberNameDiagnosticAnalyzer()
: base(IDEDiagnosticIds.UseInferredMemberNameDiagnosticId,
CodeStyleOptions.PreferInferredTupleNames,
options: ImmutableHashSet.Create<IPerLanguageOption>(CodeStyleOptions.PreferInferredAnonymousTypeMemberNames, CodeStyleOptions.PreferInferredTupleNames),
new LocalizableResourceString(nameof(FeaturesResources.Use_inferred_member_name), FeaturesResources.ResourceManager, typeof(FeaturesResources)),
new LocalizableResourceString(nameof(FeaturesResources.Member_name_can_be_simplified), FeaturesResources.ResourceManager, typeof(FeaturesResources)))
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册