Skip to content

Commit

Permalink
Use HashSet with string comparer instead of using ToUpperInvariant (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
costin-zaharia-sonarsource authored Sep 25, 2023
1 parent 31d962c commit 9ca0337
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public sealed class UnnecessaryUsings : SonarDiagnosticAnalyzer
private const string MessageFormat = "Remove this unnecessary 'using'.";

private static readonly DiagnosticDescriptor Rule = DescriptorFactory.Create(DiagnosticId, MessageFormat);
private static readonly string[] IgnoredRazorFiles =
private static readonly HashSet<string> IgnoredRazorFiles = new(StringComparer.OrdinalIgnoreCase)
{
"_IMPORTS.RAZOR",
"_VIEWIMPORTS.CSHTML"
"_Imports.razor",
"_ViewImports.cshtml"
};

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);
Expand Down Expand Up @@ -86,7 +86,7 @@ private static void CheckUnnecessaryUsings(SonarSyntaxNodeReportingContext conte
// - https://github.com/SonarSource/sonar-dotnet/issues/7959
if (usingDirective.GetFirstToken().IsKind(SyntaxKind.GlobalKeyword)
|| (GeneratedCodeRecognizer.IsRazorGeneratedFile(usingDirective.SyntaxTree)
&& IgnoredRazorFiles.Contains(Path.GetFileName(usingDirective.GetLocation().GetMappedLineSpan().Path).ToUpperInvariant())))
&& IgnoredRazorFiles.Contains(Path.GetFileName(usingDirective.GetLocation().GetMappedLineSpan().Path))))
{
continue;
}
Expand Down Expand Up @@ -228,7 +228,7 @@ private void VisitSymbol(ISymbol symbol)

internal sealed class EquivalentNameSyntax : IEquatable<EquivalentNameSyntax>
{
public NameSyntax Name { get; private set; }
public NameSyntax Name { get; }

public EquivalentNameSyntax(NameSyntax name) =>
Name = name;
Expand Down

0 comments on commit 9ca0337

Please sign in to comment.