diff --git a/.editorconfig b/.editorconfig index 3a4146cdb6..ac4d9df62d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -197,6 +197,7 @@ dotnet_diagnostic.IDE0074.severity = none dotnet_diagnostic.IDE0074WithoutSuggestion.severity = none dotnet_diagnostic.IDE0079.severity = none dotnet_diagnostic.IDE0090.severity = none +dotnet_diagnostic.IDE0130.severity = none dotnet_diagnostic.IDE0220.severity = none dotnet_diagnostic.IDE0270.severity = silent dotnet_diagnostic.IDE0290.severity = none # Use primary constructor diff --git a/src/Analyzers/CSharp/Analysis/ObjectCreation/ImplicitOrExplicitCreationAnalysis.cs b/src/Analyzers/CSharp/Analysis/ObjectCreation/ImplicitOrExplicitCreationAnalysis.cs index 38519b2ba1..fc8bacb661 100644 --- a/src/Analyzers/CSharp/Analysis/ObjectCreation/ImplicitOrExplicitCreationAnalysis.cs +++ b/src/Analyzers/CSharp/Analysis/ObjectCreation/ImplicitOrExplicitCreationAnalysis.cs @@ -15,24 +15,24 @@ namespace Roslynator.CSharp.Analysis; internal abstract class ImplicitOrExplicitCreationAnalysis { protected static readonly ImmutableDictionary _implicitToCollectionExpression = ImmutableDictionary.CreateRange(new[] - { - new KeyValuePair(DiagnosticPropertyKeys.ImplicitToCollectionExpression, null) - }); + { + new KeyValuePair(DiagnosticPropertyKeys.ImplicitToCollectionExpression, null) + }); protected static readonly ImmutableDictionary _collectionExpressionToImplicit = ImmutableDictionary.CreateRange(new[] - { - new KeyValuePair(DiagnosticPropertyKeys.CollectionExpressionToImplicit, null) - }); + { + new KeyValuePair(DiagnosticPropertyKeys.CollectionExpressionToImplicit, null) + }); protected static readonly ImmutableDictionary _explicitToCollectionExpression = ImmutableDictionary.CreateRange(new[] - { - new KeyValuePair(DiagnosticPropertyKeys.ExplicitToCollectionExpression, null) - }); + { + new KeyValuePair(DiagnosticPropertyKeys.ExplicitToCollectionExpression, null) + }); protected static readonly ImmutableDictionary _varToExplicit = ImmutableDictionary.CreateRange(new[] - { - new KeyValuePair(DiagnosticPropertyKeys.VarToExplicit, null) - }); + { + new KeyValuePair(DiagnosticPropertyKeys.VarToExplicit, null) + }); public abstract TypeStyle GetTypeStyle(ref SyntaxNodeAnalysisContext context); diff --git a/src/Analyzers/CSharp/Analysis/OptimizeLinqMethodCallAnalysis.cs b/src/Analyzers/CSharp/Analysis/OptimizeLinqMethodCallAnalysis.cs index 935cc02a0d..a3c875210b 100644 --- a/src/Analyzers/CSharp/Analysis/OptimizeLinqMethodCallAnalysis.cs +++ b/src/Analyzers/CSharp/Analysis/OptimizeLinqMethodCallAnalysis.cs @@ -937,15 +937,15 @@ public static ImmutableDictionary GetSumCountOrLength(string pro public static ImmutableDictionary Length { get; } = ImmutableDictionary.CreateRange(new[] { new KeyValuePair("PropertyName", "Length") }); public static ImmutableDictionary Sum_Count { get; } = ImmutableDictionary.CreateRange(new[] - { - new KeyValuePair("PropertyName", "Count"), - new KeyValuePair("MethodName", "Sum"), - }); + { + new KeyValuePair("PropertyName", "Count"), + new KeyValuePair("MethodName", "Sum"), + }); public static ImmutableDictionary Sum_Length { get; } = ImmutableDictionary.CreateRange(new[] - { - new KeyValuePair("PropertyName", "Length"), - new KeyValuePair("MethodName", "Sum"), - }); + { + new KeyValuePair("PropertyName", "Length"), + new KeyValuePair("MethodName", "Sum"), + }); } } diff --git a/src/Analyzers/CSharp/Analysis/UnusedParameter/UnusedParameterAnalyzer.cs b/src/Analyzers/CSharp/Analysis/UnusedParameter/UnusedParameterAnalyzer.cs index 968990ef7c..05d6fc4efa 100644 --- a/src/Analyzers/CSharp/Analysis/UnusedParameter/UnusedParameterAnalyzer.cs +++ b/src/Analyzers/CSharp/Analysis/UnusedParameter/UnusedParameterAnalyzer.cs @@ -16,12 +16,12 @@ namespace Roslynator.CSharp.Analysis.UnusedParameter; public sealed class UnusedParameterAnalyzer : BaseDiagnosticAnalyzer { private static readonly MetadataNameSet _attributes = new(new[] - { - MetadataName.Parse("System.Runtime.Serialization.OnSerializedAttribute"), - MetadataName.Parse("System.Runtime.Serialization.OnDeserializedAttribute"), - MetadataName.Parse("System.Runtime.Serialization.OnSerializingAttribute"), - MetadataName.Parse("System.Runtime.Serialization.OnDeserializingAttribute"), - }); + { + MetadataName.Parse("System.Runtime.Serialization.OnSerializedAttribute"), + MetadataName.Parse("System.Runtime.Serialization.OnDeserializedAttribute"), + MetadataName.Parse("System.Runtime.Serialization.OnSerializingAttribute"), + MetadataName.Parse("System.Runtime.Serialization.OnDeserializingAttribute"), + }); private static ImmutableArray _supportedDiagnostics; diff --git a/src/CSharp/CSharp/CSharpFacts.cs b/src/CSharp/CSharp/CSharpFacts.cs index f8fbfc2959..c28d0a3d27 100644 --- a/src/CSharp/CSharp/CSharpFacts.cs +++ b/src/CSharp/CSharp/CSharpFacts.cs @@ -12,19 +12,19 @@ namespace Roslynator.CSharp; public static class CSharpFacts { internal static ImmutableArray AssignmentExpressionKinds { get; } = ImmutableArray.CreateRange(new[] - { - SyntaxKind.SimpleAssignmentExpression, - SyntaxKind.AddAssignmentExpression, - SyntaxKind.SubtractAssignmentExpression, - SyntaxKind.MultiplyAssignmentExpression, - SyntaxKind.DivideAssignmentExpression, - SyntaxKind.ModuloAssignmentExpression, - SyntaxKind.AndAssignmentExpression, - SyntaxKind.ExclusiveOrAssignmentExpression, - SyntaxKind.OrAssignmentExpression, - SyntaxKind.LeftShiftAssignmentExpression, - SyntaxKind.RightShiftAssignmentExpression, - }); + { + SyntaxKind.SimpleAssignmentExpression, + SyntaxKind.AddAssignmentExpression, + SyntaxKind.SubtractAssignmentExpression, + SyntaxKind.MultiplyAssignmentExpression, + SyntaxKind.DivideAssignmentExpression, + SyntaxKind.ModuloAssignmentExpression, + SyntaxKind.AndAssignmentExpression, + SyntaxKind.ExclusiveOrAssignmentExpression, + SyntaxKind.OrAssignmentExpression, + SyntaxKind.LeftShiftAssignmentExpression, + SyntaxKind.RightShiftAssignmentExpression, + }); internal static string GetTitle(SyntaxNode node) { diff --git a/src/CommandLine/AssemblyFactory.cs b/src/CommandLine/AssemblyFactory.cs index 88d2fcfb4f..1d66e302e7 100644 --- a/src/CommandLine/AssemblyFactory.cs +++ b/src/CommandLine/AssemblyFactory.cs @@ -34,19 +34,19 @@ public static Assembly FromExpression( ParseName("Roslynator.Runtime"), default, List(new UsingDirectiveSyntax[] - { - UsingDirective(ParseName("System")), - UsingDirective(ParseName("System.Collections.Generic")), - UsingDirective(ParseName("System.Linq")), - UsingDirective(ParseName("System.Text")), - UsingDirective(ParseName("System.Text.RegularExpressions")), - UsingDirective(ParseName("Microsoft.CodeAnalysis")), - UsingDirective(ParseName("Microsoft.CodeAnalysis.CSharp")), + { + UsingDirective(ParseName("System")), + UsingDirective(ParseName("System.Collections.Generic")), + UsingDirective(ParseName("System.Linq")), + UsingDirective(ParseName("System.Text")), + UsingDirective(ParseName("System.Text.RegularExpressions")), + UsingDirective(ParseName("Microsoft.CodeAnalysis")), + UsingDirective(ParseName("Microsoft.CodeAnalysis.CSharp")), #if DEBUG - UsingDirective(ParseName("Roslynator")), - UsingDirective(ParseName("Roslynator.CSharp")), + UsingDirective(ParseName("Roslynator")), + UsingDirective(ParseName("Roslynator.CSharp")), #endif - }), + }), SingletonList( ClassDeclaration( default, diff --git a/src/CommandLine/Commands/FixCommand.cs b/src/CommandLine/Commands/FixCommand.cs index 8ab1c13d50..9bd247a2a5 100644 --- a/src/CommandLine/Commands/FixCommand.cs +++ b/src/CommandLine/Commands/FixCommand.cs @@ -77,10 +77,20 @@ private async Task FixAsync( IFormatProvider formatProvider = null, CancellationToken cancellationToken = default) { - foreach (string id in codeFixerOptions.IgnoredCompilerDiagnosticIds.OrderBy(f => f)) + foreach (string id in codeFixerOptions.IgnoredCompilerDiagnosticIds +#if NETFRAMEWORK + .OrderBy(f => f)) +#else + .Order()) +#endif WriteLine($"Ignore compiler diagnostic '{id}'", Verbosity.Diagnostic); - foreach (string id in codeFixerOptions.IgnoredDiagnosticIds.OrderBy(f => f)) + foreach (string id in codeFixerOptions.IgnoredDiagnosticIds +#if NETFRAMEWORK + .OrderBy(f => f)) +#else + .Order()) +#endif WriteLine($"Ignore diagnostic '{id}'", Verbosity.Diagnostic); ImmutableArray results; diff --git a/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs b/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs index b836d9be22..b864ed33bc 100644 --- a/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs +++ b/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs @@ -181,7 +181,11 @@ private bool VerifyProjectNames(Solution solution) foreach (string moniker in grouping .Select(f => f.Moniker) .Where(f => f is not null) +#if NETFRAMEWORK .OrderBy(f => f)) +#else + .Order()) +#endif { WriteLine($" {moniker}", Verbosity.Detailed); } diff --git a/src/CommandLine/FindSymbols/UnusedSymbolUtility.cs b/src/CommandLine/FindSymbols/UnusedSymbolUtility.cs index abd3892aa1..c79c1c32e3 100644 --- a/src/CommandLine/FindSymbols/UnusedSymbolUtility.cs +++ b/src/CommandLine/FindSymbols/UnusedSymbolUtility.cs @@ -14,18 +14,18 @@ namespace Roslynator; internal static class UnusedSymbolUtility { private static readonly MetadataNameSet _classAttributeSymbols = new(new[] - { - MetadataName.Parse("Microsoft.CodeAnalysis.CodeFixes.ExportCodeFixProviderAttribute"), - MetadataName.Parse("Microsoft.CodeAnalysis.CodeRefactorings.ExportCodeRefactoringProviderAttribute"), - MetadataName.Parse("Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzerAttribute"), - MetadataName.Parse("System.Composition.ExportAttribute"), - }); + { + MetadataName.Parse("Microsoft.CodeAnalysis.CodeFixes.ExportCodeFixProviderAttribute"), + MetadataName.Parse("Microsoft.CodeAnalysis.CodeRefactorings.ExportCodeRefactoringProviderAttribute"), + MetadataName.Parse("Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzerAttribute"), + MetadataName.Parse("System.Composition.ExportAttribute"), + }); private static readonly MetadataNameSet _methodAttributeSymbols = new(new[] - { - MetadataName.Parse("Xunit.FactAttribute"), - MetadataName.Parse("Xunit.TheoryAttribute"), - }); + { + MetadataName.Parse("Xunit.FactAttribute"), + MetadataName.Parse("Xunit.TheoryAttribute"), + }); public static bool CanBeUnusedSymbol(ISymbol symbol) { diff --git a/src/CommandLine/Orang/CommandLine.Core/OptionValue.cs b/src/CommandLine/Orang/CommandLine.Core/OptionValue.cs index a7c973eae0..8e8e55eb0d 100644 --- a/src/CommandLine/Orang/CommandLine.Core/OptionValue.cs +++ b/src/CommandLine/Orang/CommandLine.Core/OptionValue.cs @@ -44,8 +44,11 @@ public static string GetDefaultHelpText(bool multiline = false) where TEn .Select(f => _lowerLetterUpperLetterRegex .Replace(f.ToString(), e => e.Value.Insert(1, "-")) .ToLowerInvariant()) +#if NETFRAMEWORK .OrderBy(f => f); - +#else + .Order(); +#endif if (multiline) { return string.Join(Environment.NewLine + " ", values); diff --git a/src/Common/CSharp/Analysis/ChangeAccessibilityAnalysis.cs b/src/Common/CSharp/Analysis/ChangeAccessibilityAnalysis.cs index 3ca8934a44..1e5bf33df0 100644 --- a/src/Common/CSharp/Analysis/ChangeAccessibilityAnalysis.cs +++ b/src/Common/CSharp/Analysis/ChangeAccessibilityAnalysis.cs @@ -15,12 +15,12 @@ namespace Roslynator.CSharp.Analysis; internal static class ChangeAccessibilityAnalysis { private static readonly ImmutableDictionary> _accessibilityArrayMap = ImmutableDictionary.CreateRange(new[] - { - new KeyValuePair>(Accessibility.Public, ImmutableArray.Create(Accessibility.Public)), - new KeyValuePair>(Accessibility.Internal, ImmutableArray.Create(Accessibility.Internal)), - new KeyValuePair>(Accessibility.Protected, ImmutableArray.Create(Accessibility.Protected)), - new KeyValuePair>(Accessibility.Private, ImmutableArray.Create(Accessibility.Private)), - }); + { + new KeyValuePair>(Accessibility.Public, ImmutableArray.Create(Accessibility.Public)), + new KeyValuePair>(Accessibility.Internal, ImmutableArray.Create(Accessibility.Internal)), + new KeyValuePair>(Accessibility.Protected, ImmutableArray.Create(Accessibility.Protected)), + new KeyValuePair>(Accessibility.Private, ImmutableArray.Create(Accessibility.Private)), + }); private static ImmutableArray AvailableAccessibilities { get; } = ImmutableArray.Create( Accessibility.Public, diff --git a/src/Directory.Build.props b/src/Directory.Build.props index efae532d43..7c1e7e7a2d 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -33,7 +33,7 @@ 1.0.0 4.11.0 4.11.0 - 4.11.0 + 4.12.7 $(RoslynatorCliVersion) $(Version) $(RoslynatorPackageVersion) diff --git a/src/Tools/CodeGeneration/CSharp/CodeFixDescriptorsGenerator.cs b/src/Tools/CodeGeneration/CSharp/CodeFixDescriptorsGenerator.cs index 85a1d4b56c..dd9821795b 100644 --- a/src/Tools/CodeGeneration/CSharp/CodeFixDescriptorsGenerator.cs +++ b/src/Tools/CodeGeneration/CSharp/CodeFixDescriptorsGenerator.cs @@ -56,7 +56,7 @@ private static IEnumerable CreateMembers(IEnumerable f)) + foreach (string diagnosticId in codeFix.FixableDiagnosticIds.Order()) arguments.Add(Argument(StringLiteralExpression(diagnosticId))); FieldDeclarationSyntax fieldDeclaration = FieldDeclaration( @@ -68,7 +68,7 @@ private static IEnumerable CreateMembers(IEnumerable f))})" }, + summary: new string[] { $"{codeFix.Id} (fixes {string.Join(", ", codeFix.FixableDiagnosticIds.Order())})" }, ignoredTags: new[] { "returns", "value" }, indentation: " ", singleLineSummary: true); diff --git a/src/Tools/CodeGeneration/CSharp/CodeGenerator.cs b/src/Tools/CodeGeneration/CSharp/CodeGenerator.cs index a8758bec8b..a8f3859aab 100644 --- a/src/Tools/CodeGeneration/CSharp/CodeGenerator.cs +++ b/src/Tools/CodeGeneration/CSharp/CodeGenerator.cs @@ -43,31 +43,31 @@ public static CompilationUnitSyntax GenerateConfigOptions(IEnumerable>"), - Identifier("GetRequiredOptions"), - ParameterList(), - Block( - analyzers - .Where(f => f.ConfigOptions.Any(f => f.IsRequired)) - .OrderBy(f => f.Id, StringComparer.InvariantCulture) - .Select(f => (id: f.Id, keys: f.ConfigOptions.Where(f => f.IsRequired))) - .Select(f => - { - AnalyzerConfigOption mismatch = f.keys.FirstOrDefault(f => !options.Any(o => o.Key == f.Key)); - - Debug.Assert(mismatch.Key is null, mismatch.Key); - - IEnumerable optionKeys = f.keys - .Join(options, f => f.Key, f => f.Key, (_, g) => g) - .Select(f => $"ConfigOptionKeys.{f.Id}"); - - return YieldReturnStatement( - ParseExpression($"new KeyValuePair(\"{f.id}\", JoinOptionKeys({string.Join(", ", optionKeys)}))")); - }))), - }) + { + MethodDeclaration( + Modifiers.Private_Static(), + ParseTypeName("IEnumerable>"), + Identifier("GetRequiredOptions"), + ParameterList(), + Block( + analyzers + .Where(f => f.ConfigOptions.Any(f => f.IsRequired)) + .OrderBy(f => f.Id, StringComparer.InvariantCulture) + .Select(f => (id: f.Id, keys: f.ConfigOptions.Where(f => f.IsRequired))) + .Select(f => + { + AnalyzerConfigOption mismatch = f.keys.FirstOrDefault(f => !options.Any(o => o.Key == f.Key)); + + Debug.Assert(mismatch.Key is null, mismatch.Key); + + IEnumerable optionKeys = f.keys + .Join(options, f => f.Key, f => f.Key, (_, g) => g) + .Select(f => $"ConfigOptionKeys.{f.Id}"); + + return YieldReturnStatement( + ParseExpression($"new KeyValuePair(\"{f.id}\", JoinOptionKeys({string.Join(", ", optionKeys)}))")); + }))), + }) .ToSyntaxList()))); compilationUnit = compilationUnit.NormalizeWhitespace(); diff --git a/src/Tools/Metadata/MetadataFile.cs b/src/Tools/Metadata/MetadataFile.cs index c2b2a13e8e..aa17991b39 100644 --- a/src/Tools/Metadata/MetadataFile.cs +++ b/src/Tools/Metadata/MetadataFile.cs @@ -283,7 +283,7 @@ public static IEnumerable ReadOptions(string filePath) ?? Enumerable.Empty(); string defaultValue = element.Element("DefaultValue")?.Value ?? values.FirstOrDefault(f => f.IsDefault).Value; - string defaultValuePlaceholder = element.Element("ValuePlaceholder")?.Value ?? string.Join("|", values.Select(f => f.Value).OrderBy(f => f)); + string defaultValuePlaceholder = element.Element("ValuePlaceholder")?.Value ?? string.Join("|", values.Select(f => f.Value).Order()); var analyzerOption = new AnalyzerOptionMetadata( Id: id, diff --git a/src/Workspaces.Core/Spelling/Core/TextUtility.cs b/src/Workspaces.Core/Spelling/Core/TextUtility.cs index 8509a56c58..26e9cce102 100644 --- a/src/Workspaces.Core/Spelling/Core/TextUtility.cs +++ b/src/Workspaces.Core/Spelling/Core/TextUtility.cs @@ -39,7 +39,7 @@ public static string ReplaceRange(string value, string replacement, int index, i return value.Remove(index) + replacement - + value.Substring(endIndex, value.Length - endIndex); + + value.Substring(endIndex); } public static string SetTextCasing(string s, TextCasing textCasing) diff --git a/src/Workspaces.Core/Spelling/SpellingAnalysisContext.cs b/src/Workspaces.Core/Spelling/SpellingAnalysisContext.cs index d892c78fc8..7e5ddd30ed 100644 --- a/src/Workspaces.Core/Spelling/SpellingAnalysisContext.cs +++ b/src/Workspaces.Core/Spelling/SpellingAnalysisContext.cs @@ -80,18 +80,18 @@ private void ProcessMatches( if (match.Parent is not null) { properties = ImmutableDictionary.CreateRange(new[] - { - new KeyValuePair("Value", match.Value), - new KeyValuePair("Parent", match.Parent), - new KeyValuePair("ParentIndex", (span.Start + match.ParentIndex).ToString(CultureInfo.InvariantCulture)), - }); + { + new KeyValuePair("Value", match.Value), + new KeyValuePair("Parent", match.Parent), + new KeyValuePair("ParentIndex", (span.Start + match.ParentIndex).ToString(CultureInfo.InvariantCulture)), + }); } else { properties = ImmutableDictionary.CreateRange(new[] - { - new KeyValuePair("Value", match.Value) - }); + { + new KeyValuePair("Value", match.Value) + }); } Diagnostic diagnostic = Diagnostic.Create( @@ -109,10 +109,10 @@ private void ProcessMatches(ImmutableArray matches, SyntaxTree sy foreach (SpellingMatch match in matches) { ImmutableDictionary properties = ImmutableDictionary.CreateRange(new[] - { - new KeyValuePair("Value", match.Value), - new KeyValuePair("FilePath", syntaxTree.FilePath), - }); + { + new KeyValuePair("Value", match.Value), + new KeyValuePair("FilePath", syntaxTree.FilePath), + }); Diagnostic diagnostic = Diagnostic.Create( SpellcheckAnalyzer.DiagnosticDescriptor,