-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMen016AvoidTopLevelStatements.cs
56 lines (38 loc) · 1.6 KB
/
Men016AvoidTopLevelStatements.cs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
namespace Menees.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class Men016AvoidTopLevelStatements : Analyzer
{
#region Public Constants
public const string DiagnosticId = "MEN016";
#endregion
#region Private Data Members
private static readonly LocalizableString Title =
new LocalizableResourceString(nameof(Resources.Men016Title), Resources.ResourceManager, typeof(Resources));
private static readonly LocalizableString MessageFormat =
new LocalizableResourceString(nameof(Resources.Men016MessageFormat), Resources.ResourceManager, typeof(Resources));
private static readonly LocalizableString Description =
new LocalizableResourceString(nameof(Resources.Men016Description), Resources.ResourceManager, typeof(Resources));
private static readonly DiagnosticDescriptor Rule =
new(DiagnosticId, Title, MessageFormat, Rules.Usage, DiagnosticSeverity.Warning, Rules.EnabledByDefault, Description);
#endregion
#region Public Properties
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);
#endregion
#region Public Methods
public override void Initialize(AnalysisContext context)
{
base.Initialize(context);
context.RegisterSyntaxNodeActionHonorExclusions(this, HandleGlobalStatement, SyntaxKind.GlobalStatement);
}
#endregion
#region Private Methods
private static void HandleGlobalStatement(SyntaxNodeAnalysisContext context)
{
if (context.Node is GlobalStatementSyntax statement)
{
Location location = statement.GetLocation();
context.ReportDiagnostic(Diagnostic.Create(Rule, location));
}
}
#endregion
}