Created
June 3, 2015 03:41
-
-
Save joymon/66d36b58afd98f3df1cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.CodeAnalysis; | |
using Microsoft.CodeAnalysis.Diagnostics; | |
using System.Collections.Immutable; | |
using System.Linq; | |
namespace JoymonsCode | |
{ | |
public class TypeNameShouldStartWithCapitalLetterDiagnosticAnalyzer : DiagnosticAnalyzer | |
{ | |
internal const string DiagnosticId = "TypeNameShouldStartWithCapitalLetter"; | |
internal static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor( | |
id: DiagnosticId, | |
title: "Type name starts with lowercase letters", | |
messageFormat: "Type name '{0}' starts with lowercase letters", | |
category: "Naming", | |
defaultSeverity: DiagnosticSeverity.Warning, | |
isEnabledByDefault: true); | |
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get { return ImmutableArray.Create(Rule); } } | |
public override void Initialize(AnalysisContext context) | |
{ | |
context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.NamedType); | |
} | |
private void AnalyzeSymbol(SymbolAnalysisContext context) | |
{ | |
if (char.IsLower(context.Symbol.Name.First())) | |
{ | |
var diagnostic = Diagnostic.Create(Rule, context.Symbol.Locations[0], context.Symbol.Name); | |
context.ReportDiagnostic(diagnostic); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment