-
-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathMissingPolyfillAnalyzer.cs
More file actions
34 lines (29 loc) · 1.06 KB
/
Copy pathMissingPolyfillAnalyzer.cs
File metadata and controls
34 lines (29 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
namespace TUnit.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class MissingPolyfillAnalyzer : ConcurrentDiagnosticAnalyzer
{
private static readonly string[] RequiredTypes =
[
"System.Runtime.CompilerServices.ModuleInitializerAttribute",
];
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } =
ImmutableArray.Create(Rules.MissingPolyfillPackage);
protected override void InitializeInternal(AnalysisContext context)
{
context.RegisterCompilationAction(AnalyzeCompilation);
}
private static void AnalyzeCompilation(CompilationAnalysisContext context)
{
foreach (var typeName in RequiredTypes)
{
if (context.Compilation.GetTypeByMetadataName(typeName) is null)
{
context.ReportDiagnostic(
Diagnostic.Create(Rules.MissingPolyfillPackage, Location.None, typeName));
}
}
}
}