Skip to content

Commit

Permalink
Bump Roslynator analyzers reference to 4.12.7 (#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Oct 4, 2024
1 parent ad59197 commit eed662a
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 111 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ namespace Roslynator.CSharp.Analysis;
internal abstract class ImplicitOrExplicitCreationAnalysis
{
protected static readonly ImmutableDictionary<string, string> _implicitToCollectionExpression = ImmutableDictionary.CreateRange(new[]
{
new KeyValuePair<string, string>(DiagnosticPropertyKeys.ImplicitToCollectionExpression, null)
});
{
new KeyValuePair<string, string>(DiagnosticPropertyKeys.ImplicitToCollectionExpression, null)
});

protected static readonly ImmutableDictionary<string, string> _collectionExpressionToImplicit = ImmutableDictionary.CreateRange(new[]
{
new KeyValuePair<string, string>(DiagnosticPropertyKeys.CollectionExpressionToImplicit, null)
});
{
new KeyValuePair<string, string>(DiagnosticPropertyKeys.CollectionExpressionToImplicit, null)
});

protected static readonly ImmutableDictionary<string, string> _explicitToCollectionExpression = ImmutableDictionary.CreateRange(new[]
{
new KeyValuePair<string, string>(DiagnosticPropertyKeys.ExplicitToCollectionExpression, null)
});
{
new KeyValuePair<string, string>(DiagnosticPropertyKeys.ExplicitToCollectionExpression, null)
});

protected static readonly ImmutableDictionary<string, string> _varToExplicit = ImmutableDictionary.CreateRange(new[]
{
new KeyValuePair<string, string>(DiagnosticPropertyKeys.VarToExplicit, null)
});
{
new KeyValuePair<string, string>(DiagnosticPropertyKeys.VarToExplicit, null)
});

public abstract TypeStyle GetTypeStyle(ref SyntaxNodeAnalysisContext context);

Expand Down
16 changes: 8 additions & 8 deletions src/Analyzers/CSharp/Analysis/OptimizeLinqMethodCallAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -937,15 +937,15 @@ public static ImmutableDictionary<string, string> GetSumCountOrLength(string pro
public static ImmutableDictionary<string, string> Length { get; } = ImmutableDictionary.CreateRange(new[] { new KeyValuePair<string, string>("PropertyName", "Length") });

public static ImmutableDictionary<string, string> Sum_Count { get; } = ImmutableDictionary.CreateRange(new[]
{
new KeyValuePair<string, string>("PropertyName", "Count"),
new KeyValuePair<string, string>("MethodName", "Sum"),
});
{
new KeyValuePair<string, string>("PropertyName", "Count"),
new KeyValuePair<string, string>("MethodName", "Sum"),
});

public static ImmutableDictionary<string, string> Sum_Length { get; } = ImmutableDictionary.CreateRange(new[]
{
new KeyValuePair<string, string>("PropertyName", "Length"),
new KeyValuePair<string, string>("MethodName", "Sum"),
});
{
new KeyValuePair<string, string>("PropertyName", "Length"),
new KeyValuePair<string, string>("MethodName", "Sum"),
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<DiagnosticDescriptor> _supportedDiagnostics;

Expand Down
26 changes: 13 additions & 13 deletions src/CSharp/CSharp/CSharpFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ namespace Roslynator.CSharp;
public static class CSharpFacts
{
internal static ImmutableArray<SyntaxKind> 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)
{
Expand Down
22 changes: 11 additions & 11 deletions src/CommandLine/AssemblyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemberDeclarationSyntax>(
ClassDeclaration(
default,
Expand Down
14 changes: 12 additions & 2 deletions src/CommandLine/Commands/FixCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,20 @@ private async Task<FixCommandResult> 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<ProjectFixResult> results;
Expand Down
4 changes: 4 additions & 0 deletions src/CommandLine/Commands/MSBuildWorkspaceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
20 changes: 10 additions & 10 deletions src/CommandLine/FindSymbols/UnusedSymbolUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 4 additions & 1 deletion src/CommandLine/Orang/CommandLine.Core/OptionValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public static string GetDefaultHelpText<TEnum>(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);
Expand Down
12 changes: 6 additions & 6 deletions src/Common/CSharp/Analysis/ChangeAccessibilityAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ namespace Roslynator.CSharp.Analysis;
internal static class ChangeAccessibilityAnalysis
{
private static readonly ImmutableDictionary<Accessibility, ImmutableArray<Accessibility>> _accessibilityArrayMap = ImmutableDictionary.CreateRange(new[]
{
new KeyValuePair<Accessibility, ImmutableArray<Accessibility>>(Accessibility.Public, ImmutableArray.Create(Accessibility.Public)),
new KeyValuePair<Accessibility, ImmutableArray<Accessibility>>(Accessibility.Internal, ImmutableArray.Create(Accessibility.Internal)),
new KeyValuePair<Accessibility, ImmutableArray<Accessibility>>(Accessibility.Protected, ImmutableArray.Create(Accessibility.Protected)),
new KeyValuePair<Accessibility, ImmutableArray<Accessibility>>(Accessibility.Private, ImmutableArray.Create(Accessibility.Private)),
});
{
new KeyValuePair<Accessibility, ImmutableArray<Accessibility>>(Accessibility.Public, ImmutableArray.Create(Accessibility.Public)),
new KeyValuePair<Accessibility, ImmutableArray<Accessibility>>(Accessibility.Internal, ImmutableArray.Create(Accessibility.Internal)),
new KeyValuePair<Accessibility, ImmutableArray<Accessibility>>(Accessibility.Protected, ImmutableArray.Create(Accessibility.Protected)),
new KeyValuePair<Accessibility, ImmutableArray<Accessibility>>(Accessibility.Private, ImmutableArray.Create(Accessibility.Private)),
});

private static ImmutableArray<Accessibility> AvailableAccessibilities { get; } = ImmutableArray.Create(
Accessibility.Public,
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<Version Condition="'$(Version)' == ''">1.0.0</Version>
<RoslynatorCliRoslynVersion>4.11.0</RoslynatorCliRoslynVersion>
<RoslynatorTestingRoslynVersion>4.11.0</RoslynatorTestingRoslynVersion>
<RoslynatorAnalyzersPackageReferenceVersion>4.11.0</RoslynatorAnalyzersPackageReferenceVersion>
<RoslynatorAnalyzersPackageReferenceVersion>4.12.7</RoslynatorAnalyzersPackageReferenceVersion>
<RoslynatorCliPackageVersion>$(RoslynatorCliVersion)</RoslynatorCliPackageVersion>
<RoslynatorPackageVersion>$(Version)</RoslynatorPackageVersion>
<RoslynatorVersion>$(RoslynatorPackageVersion)</RoslynatorVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static IEnumerable<MemberDeclarationSyntax> CreateMembers(IEnumerable<Co
BooleanLiteralExpression(true)),
};

foreach (string diagnosticId in codeFix.FixableDiagnosticIds.OrderBy(f => f))
foreach (string diagnosticId in codeFix.FixableDiagnosticIds.Order())
arguments.Add(Argument(StringLiteralExpression(diagnosticId)));

FieldDeclarationSyntax fieldDeclaration = FieldDeclaration(
Expand All @@ -68,7 +68,7 @@ private static IEnumerable<MemberDeclarationSyntax> CreateMembers(IEnumerable<Co
ArgumentList(arguments.ToSeparatedSyntaxList())));

var settings = new DocumentationCommentGeneratorSettings(
summary: new string[] { $"{codeFix.Id} (fixes {string.Join(", ", codeFix.FixableDiagnosticIds.OrderBy(f => f))})" },
summary: new string[] { $"{codeFix.Id} (fixes {string.Join(", ", codeFix.FixableDiagnosticIds.Order())})" },
ignoredTags: new[] { "returns", "value" },
indentation: " ",
singleLineSummary: true);
Expand Down
50 changes: 25 additions & 25 deletions src/Tools/CodeGeneration/CSharp/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,31 @@ public static CompilationUnitSyntax GenerateConfigOptions(IEnumerable<AnalyzerOp
.AddObsoleteAttributeIf(f.IsObsolete);
})
.Concat(new MemberDeclarationSyntax[]
{
MethodDeclaration(
Modifiers.Private_Static(),
ParseTypeName("IEnumerable<KeyValuePair<string, string>>"),
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<string> optionKeys = f.keys
.Join(options, f => f.Key, f => f.Key, (_, g) => g)
.Select(f => $"ConfigOptionKeys.{f.Id}");

return YieldReturnStatement(
ParseExpression($"new KeyValuePair<string, string>(\"{f.id}\", JoinOptionKeys({string.Join(", ", optionKeys)}))"));
}))),
})
{
MethodDeclaration(
Modifiers.Private_Static(),
ParseTypeName("IEnumerable<KeyValuePair<string, string>>"),
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<string> optionKeys = f.keys
.Join(options, f => f.Key, f => f.Key, (_, g) => g)
.Select(f => $"ConfigOptionKeys.{f.Id}");

return YieldReturnStatement(
ParseExpression($"new KeyValuePair<string, string>(\"{f.id}\", JoinOptionKeys({string.Join(", ", optionKeys)}))"));
}))),
})
.ToSyntaxList())));

compilationUnit = compilationUnit.NormalizeWhitespace();
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/Metadata/MetadataFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public static IEnumerable<AnalyzerOptionMetadata> ReadOptions(string filePath)
?? Enumerable.Empty<AnalyzerOptionValueMetadata>();

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,
Expand Down
2 changes: 1 addition & 1 deletion src/Workspaces.Core/Spelling/Core/TextUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit eed662a

Please sign in to comment.