Skip to content

Commit f5f41e2

Browse files
author
Christian Käser
committed
Use DocumentationCulture in SA1642ConstructorSummaryDocumentationMustBeginWithStandardText
1 parent 42f7b35 commit f5f41e2

4 files changed

Lines changed: 155 additions & 7 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.Designer.cs

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.de-DE.resx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@
123123
<data name="DestructorStandardTextSecondPart" xml:space="preserve">
124124
<value> Klasse.</value>
125125
</data>
126+
<data name="NonPrivateConstructorStandardTextFirstPart" xml:space="preserve">
127+
<value>Initialisiert eine neue Instanz der </value>
128+
</data>
129+
<data name="NonPrivateConstructorStandardTextSecondPart" xml:space="preserve">
130+
<value> {0}</value>
131+
</data>
132+
<data name="PrivateConstructorStandardTextFirstPart" xml:space="preserve">
133+
<value>Verhindert, dass eine Standardinstanz der </value>
134+
</data>
135+
<data name="PrivateConstructorStandardTextSecondPart" xml:space="preserve">
136+
<value> {0} erstellt wird</value>
137+
</data>
126138
<data name="StartingTextGets" xml:space="preserve">
127139
<value>Holt</value>
128140
</data>
@@ -141,4 +153,16 @@
141153
<data name="StartingTextSetsWhether" xml:space="preserve">
142154
<value>Setzt einen Wert, der angibt, ob</value>
143155
</data>
156+
<data name="StaticConstructorStandardTextFirstPart" xml:space="preserve">
157+
<value>Initialisiert statische Member der </value>
158+
</data>
159+
<data name="StaticConstructorStandardTextSecondPart" xml:space="preserve">
160+
<value> {0}.</value>
161+
</data>
162+
<data name="TypeTextClass" xml:space="preserve">
163+
<value>Klasse</value>
164+
</data>
165+
<data name="TypeTextStruct" xml:space="preserve">
166+
<value>Struktur</value>
167+
</data>
144168
</root>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.resx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@
126126
<data name="InheritdocCodeFix" xml:space="preserve">
127127
<value>Inherit documentation</value>
128128
</data>
129+
<data name="NonPrivateConstructorStandardTextFirstPart" xml:space="preserve">
130+
<value>Initializes a new instance of the </value>
131+
</data>
132+
<data name="NonPrivateConstructorStandardTextSecondPart" xml:space="preserve">
133+
<value> {0}</value>
134+
</data>
135+
<data name="PrivateConstructorStandardTextFirstPart" xml:space="preserve">
136+
<value>Prevents a default instance of the </value>
137+
</data>
138+
<data name="PrivateConstructorStandardTextSecondPart" xml:space="preserve">
139+
<value> {0} from being created</value>
140+
</data>
129141
<data name="PropertySummaryStartTextCodeFix" xml:space="preserve">
130142
<value>Add standard text</value>
131143
</data>
@@ -309,4 +321,16 @@
309321
<data name="StartingTextSetsWhether" xml:space="preserve">
310322
<value>Sets a value indicating whether</value>
311323
</data>
324+
<data name="StaticConstructorStandardTextFirstPart" xml:space="preserve">
325+
<value>Initializes static members of the </value>
326+
</data>
327+
<data name="StaticConstructorStandardTextSecondPart" xml:space="preserve">
328+
<value> {0}.</value>
329+
</data>
330+
<data name="TypeTextClass" xml:space="preserve">
331+
<value>class</value>
332+
</data>
333+
<data name="TypeTextStruct" xml:space="preserve">
334+
<value>struct</value>
335+
</data>
312336
</root>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1642ConstructorSummaryDocumentationMustBeginWithStandardText.cs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ namespace StyleCop.Analyzers.DocumentationRules
55
{
66
using System;
77
using System.Collections.Immutable;
8+
using System.Globalization;
89
using System.Linq;
10+
using System.Threading;
11+
912
using Microsoft.CodeAnalysis;
1013
using Microsoft.CodeAnalysis.CSharp;
1114
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -170,29 +173,54 @@ private static void HandleConstructorDeclaration(SyntaxNodeAnalysisContext conte
170173
{
171174
var constructorDeclarationSyntax = (ConstructorDeclarationSyntax)context.Node;
172175

176+
var settings = context.Options.GetStyleCopSettings(CancellationToken.None);
177+
var culture = new CultureInfo(settings.DocumentationRules.DocumentationCulture);
178+
var resourceManager = DocumentationResources.ResourceManager;
179+
173180
bool isStruct = constructorDeclarationSyntax.Parent?.IsKind(SyntaxKind.StructDeclaration) ?? false;
181+
var typeKindText = resourceManager.GetString(isStruct ? "TypeTextStruct" : "TypeTextClass", culture);
174182

175183
if (constructorDeclarationSyntax.Modifiers.Any(SyntaxKind.StaticKeyword))
176184
{
177-
string secondPartText = isStruct ? " struct." : " class.";
178-
HandleDeclaration(context, StaticConstructorStandardText, secondPartText, Descriptor);
185+
HandleDeclaration(
186+
context,
187+
resourceManager.GetString("StaticConstructorStandardTextFirstPart", culture),
188+
string.Format(resourceManager.GetString("StaticConstructorStandardTextSecondPart", culture), typeKindText),
189+
Descriptor);
179190
}
180191
else if (constructorDeclarationSyntax.Modifiers.Any(SyntaxKind.PrivateKeyword))
181192
{
182-
string typeKindText = isStruct ? " struct" : " class";
193+
var privateConstructorMatch = HandleDeclaration(
194+
context,
195+
resourceManager.GetString("PrivateConstructorStandardTextFirstPart", culture),
196+
string.Format(
197+
resourceManager.GetString("PrivateConstructorStandardTextSecondPart", culture),
198+
typeKindText),
199+
null);
183200

184-
if (HandleDeclaration(context, PrivateConstructorStandardText[0], typeKindText + PrivateConstructorStandardText[1], null) == MatchResult.FoundMatch)
201+
if (privateConstructorMatch == MatchResult.FoundMatch)
185202
{
186203
return;
187204
}
188205

189206
// also allow the non-private wording for private constructors
190-
HandleDeclaration(context, NonPrivateConstructorStandardText, typeKindText, Descriptor);
207+
HandleDeclaration(
208+
context,
209+
resourceManager.GetString("NonPrivateConstructorStandardTextFirstPart", culture),
210+
string.Format(
211+
resourceManager.GetString("NonPrivateConstructorStandardTextSecondPart", culture),
212+
typeKindText),
213+
Descriptor);
191214
}
192215
else
193216
{
194-
string typeKindText = isStruct ? " struct" : " class";
195-
HandleDeclaration(context, NonPrivateConstructorStandardText, typeKindText, Descriptor);
217+
HandleDeclaration(
218+
context,
219+
resourceManager.GetString("NonPrivateConstructorStandardTextFirstPart", culture),
220+
string.Format(
221+
resourceManager.GetString("NonPrivateConstructorStandardTextSecondPart", culture),
222+
typeKindText),
223+
Descriptor);
196224
}
197225
}
198226
}

0 commit comments

Comments
 (0)