@@ -12,6 +12,7 @@ namespace StyleCop.Analyzers.NamingRules
12
12
using Microsoft . CodeAnalysis . Diagnostics ;
13
13
using StyleCop . Analyzers . Helpers ;
14
14
using StyleCop . Analyzers . Lightup ;
15
+ using StyleCop . Analyzers . Settings . ObjectModel ;
15
16
16
17
/// <summary>
17
18
/// The name of a C# element does not begin with an upper-case letter.
@@ -29,6 +30,9 @@ namespace StyleCop.Analyzers.NamingRules
29
30
/// class. A <c>NativeMethods</c> class is any class which contains a name ending in <c>NativeMethods</c>, and is
30
31
/// intended as a placeholder for Win32 or COM wrappers. StyleCop will ignore this violation if the item is placed
31
32
/// within a <c>NativeMethods</c> class.</para>
33
+ ///
34
+ /// <para>For namespace components that begin with a small letter, due to branding issues or other reasons, add the
35
+ /// term to the <c>allowedNamespaceComponents</c> list.</para>
32
36
/// </remarks>
33
37
[ DiagnosticAnalyzer ( LanguageNames . CSharp ) ]
34
38
internal class SA1300ElementMustBeginWithUpperCaseLetter : DiagnosticAnalyzer
@@ -45,7 +49,7 @@ internal class SA1300ElementMustBeginWithUpperCaseLetter : DiagnosticAnalyzer
45
49
private static readonly DiagnosticDescriptor Descriptor =
46
50
new DiagnosticDescriptor ( DiagnosticId , Title , MessageFormat , AnalyzerCategory . NamingRules , DiagnosticSeverity . Warning , AnalyzerConstants . EnabledByDefault , Description , HelpLink ) ;
47
51
48
- private static readonly Action < SyntaxNodeAnalysisContext > NamespaceDeclarationAction = HandleNamespaceDeclaration ;
52
+ private static readonly Action < SyntaxNodeAnalysisContext , StyleCopSettings > NamespaceDeclarationAction = HandleNamespaceDeclaration ;
49
53
private static readonly Action < SyntaxNodeAnalysisContext > ClassDeclarationAction = HandleClassDeclaration ;
50
54
private static readonly Action < SyntaxNodeAnalysisContext > EnumDeclarationAction = HandleEnumDeclaration ;
51
55
private static readonly Action < SyntaxNodeAnalysisContext > EnumMemberDeclarationAction = HandleEnumMemberDeclaration ;
@@ -82,13 +86,13 @@ public override void Initialize(AnalysisContext context)
82
86
context . RegisterSyntaxNodeAction ( PropertyDeclarationAction , SyntaxKind . PropertyDeclaration ) ;
83
87
}
84
88
85
- private static void HandleNamespaceDeclaration ( SyntaxNodeAnalysisContext context )
89
+ private static void HandleNamespaceDeclaration ( SyntaxNodeAnalysisContext context , StyleCopSettings settings )
86
90
{
87
91
NameSyntax nameSyntax = ( ( NamespaceDeclarationSyntax ) context . Node ) . Name ;
88
- CheckNameSyntax ( context , nameSyntax ) ;
92
+ CheckNamespaceNameSyntax ( context , nameSyntax , settings ) ;
89
93
}
90
94
91
- private static void CheckNameSyntax ( SyntaxNodeAnalysisContext context , NameSyntax nameSyntax )
95
+ private static void CheckNamespaceNameSyntax ( SyntaxNodeAnalysisContext context , NameSyntax nameSyntax , StyleCopSettings settings )
92
96
{
93
97
if ( nameSyntax == null || nameSyntax . IsMissing )
94
98
{
@@ -97,12 +101,13 @@ private static void CheckNameSyntax(SyntaxNodeAnalysisContext context, NameSynta
97
101
98
102
if ( nameSyntax is QualifiedNameSyntax qualifiedNameSyntax )
99
103
{
100
- CheckNameSyntax ( context , qualifiedNameSyntax . Left ) ;
101
- CheckNameSyntax ( context , qualifiedNameSyntax . Right ) ;
104
+ CheckNamespaceNameSyntax ( context , qualifiedNameSyntax . Left , settings ) ;
105
+ CheckNamespaceNameSyntax ( context , qualifiedNameSyntax . Right , settings ) ;
102
106
return ;
103
107
}
104
108
105
- if ( nameSyntax is SimpleNameSyntax simpleNameSyntax )
109
+ if ( nameSyntax is SimpleNameSyntax simpleNameSyntax &&
110
+ ! settings . NamingRules . AllowedNamespaceComponents . Contains ( simpleNameSyntax . Identifier . ValueText ) )
106
111
{
107
112
CheckElementNameToken ( context , simpleNameSyntax . Identifier ) ;
108
113
return ;
0 commit comments