Skip to content

Commit 396d8f3

Browse files
authored
Fix duplicate analyzers (#1477)
1 parent bf87ca2 commit 396d8f3

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Fix analyzer [RCS1108](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1108) ([PR](https://github.com/dotnet/roslynator/pull/1469))
1313
- Fix analyzer [RCS1201](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1201) ([PR](https://github.com/dotnet/roslynator/pull/1470))
1414
- Fix analyzer [RCS0012](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0012) ([PR](https://github.com/dotnet/roslynator/pull/1472))
15+
- [CLI] Fix duplicate analyzers ([PR](https://github.com/dotnet/roslynator/pull/1477))
1516

1617
## [4.12.3] - 2024-05-10
1718

src/Workspaces.Core/AnalyzerLoader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public ImmutableArray<DiagnosticAnalyzer> GetAnalyzers(Project project)
6464

6565
private (ImmutableArray<DiagnosticAnalyzer> analyzers, ImmutableArray<CodeFixProvider> fixers) GetAnalyzersAndFixers(
6666
Project project,
67-
bool loadFixers = true)
67+
bool loadFixers)
6868
{
6969
string language = project.Language;
7070

@@ -104,6 +104,7 @@ public ImmutableArray<DiagnosticAnalyzer> GetAnalyzers(Project project)
104104
.Distinct()
105105
.OfType<AnalyzerFileReference>()
106106
.Select(f => f.GetAssembly())
107+
.Distinct(AssemblyFullNameComparer.Instance)
107108
.Where(f => !_defaultAssemblies.ContainsKey(f.FullName)))
108109
{
109110
if (!_cache.TryGetValue(assembly.FullName, out AnalyzerAssembly analyzerAssembly))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Reflection;
6+
7+
namespace Roslynator;
8+
9+
internal sealed class AssemblyFullNameComparer : EqualityComparer<Assembly>
10+
{
11+
public static AssemblyFullNameComparer Instance { get; } = new();
12+
13+
public override bool Equals(Assembly x, Assembly y)
14+
{
15+
return StringComparer.Ordinal.Equals(x.FullName, y.FullName);
16+
}
17+
18+
public override int GetHashCode(Assembly obj)
19+
{
20+
return StringComparer.Ordinal.GetHashCode(obj.FullName);
21+
}
22+
}

0 commit comments

Comments
 (0)