Skip to content

Commit

Permalink
Fix duplicate analyzers (#1477)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt committed Jun 1, 2024
1 parent bf87ca2 commit 396d8f3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix analyzer [RCS1108](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1108) ([PR](https://github.com/dotnet/roslynator/pull/1469))
- Fix analyzer [RCS1201](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1201) ([PR](https://github.com/dotnet/roslynator/pull/1470))
- Fix analyzer [RCS0012](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0012) ([PR](https://github.com/dotnet/roslynator/pull/1472))
- [CLI] Fix duplicate analyzers ([PR](https://github.com/dotnet/roslynator/pull/1477))

## [4.12.3] - 2024-05-10

Expand Down
3 changes: 2 additions & 1 deletion src/Workspaces.Core/AnalyzerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ImmutableArray<DiagnosticAnalyzer> GetAnalyzers(Project project)

private (ImmutableArray<DiagnosticAnalyzer> analyzers, ImmutableArray<CodeFixProvider> fixers) GetAnalyzersAndFixers(
Project project,
bool loadFixers = true)
bool loadFixers)
{
string language = project.Language;

Expand Down Expand Up @@ -104,6 +104,7 @@ public ImmutableArray<DiagnosticAnalyzer> GetAnalyzers(Project project)
.Distinct()
.OfType<AnalyzerFileReference>()
.Select(f => f.GetAssembly())
.Distinct(AssemblyFullNameComparer.Instance)
.Where(f => !_defaultAssemblies.ContainsKey(f.FullName)))
{
if (!_cache.TryGetValue(assembly.FullName, out AnalyzerAssembly analyzerAssembly))
Expand Down
22 changes: 22 additions & 0 deletions src/Workspaces.Core/AssemblyFullNameComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Reflection;

namespace Roslynator;

internal sealed class AssemblyFullNameComparer : EqualityComparer<Assembly>
{
public static AssemblyFullNameComparer Instance { get; } = new();

public override bool Equals(Assembly x, Assembly y)
{
return StringComparer.Ordinal.Equals(x.FullName, y.FullName);
}

public override int GetHashCode(Assembly obj)
{
return StringComparer.Ordinal.GetHashCode(obj.FullName);
}
}

0 comments on commit 396d8f3

Please sign in to comment.