Skip to content

Commit ddc2e31

Browse files
authored
Merge pull request #2228 from dfyx/feature/implement-2227-localize-parameter-not-used
Implement #2227: SA1625 should accept localized "The parameter is not used."
2 parents 2a966c1 + aa596ec commit ddc2e31

10 files changed

Lines changed: 45 additions & 5 deletions

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

Lines changed: 9 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<data name="NonPrivateConstructorStandardTextSecondPart" xml:space="preserve">
130130
<value> {0}</value>
131131
</data>
132+
<data name="ParameterNotUsed" xml:space="preserve">
133+
<value>Dieser Parameter wird nicht verwendet.</value>
134+
</data>
132135
<data name="PrivateConstructorStandardTextFirstPart" xml:space="preserve">
133136
<value>Verhindert, dass eine Standardinstanz der </value>
134137
</data>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.en-GB.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<data name="NonPrivateConstructorStandardTextSecondPart" xml:space="preserve">
130130
<value> {0}</value>
131131
</data>
132+
<data name="ParameterNotUsed" xml:space="preserve">
133+
<value>The parameter is not used.</value>
134+
</data>
132135
<data name="PrivateConstructorStandardTextFirstPart" xml:space="preserve">
133136
<value>Prevents a default instance of the </value>
134137
</data>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.es-MX.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<data name="NonPrivateConstructorStandardTextSecondPart" xml:space="preserve">
130130
<value />
131131
</data>
132+
<data name="ParameterNotUsed" xml:space="preserve">
133+
<value>El parámetro no se usa.</value>
134+
</data>
132135
<data name="PrivateConstructorStandardTextFirstPart" xml:space="preserve">
133136
<value>Previene una instancia por defecto de la {0} </value>
134137
</data>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.fr-FR.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<data name="NonPrivateConstructorStandardTextSecondPart" xml:space="preserve">
130130
<value />
131131
</data>
132+
<data name="ParameterNotUsed" xml:space="preserve">
133+
<value>Le paramètre n'est pas utilisé.</value>
134+
</data>
132135
<data name="PrivateConstructorStandardTextFirstPart" xml:space="preserve">
133136
<value>Empêche la création d'une instance par défaut de la {0} </value>
134137
</data>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.pl-PL.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<data name="NonPrivateConstructorStandardTextSecondPart" xml:space="preserve">
130130
<value />
131131
</data>
132+
<data name="ParameterNotUsed" xml:space="preserve">
133+
<value>Parametr nie jest używany.</value>
134+
</data>
132135
<data name="PrivateConstructorStandardTextFirstPart" xml:space="preserve">
133136
<value>Uniemożliwia utworzenie domyślnej instancji {0} </value>
134137
</data>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.pt-BR.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<data name="NonPrivateConstructorStandardTextSecondPart" xml:space="preserve">
130130
<value />
131131
</data>
132+
<data name="ParameterNotUsed" xml:space="preserve">
133+
<value>O parâmetro não é usado.</value>
134+
</data>
132135
<data name="PrivateConstructorStandardTextFirstPart" xml:space="preserve">
133136
<value>Evita que uma instância default da {0} </value>
134137
</data>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
<data name="NonPrivateConstructorStandardTextSecondPart" xml:space="preserve">
133133
<value> {0}</value>
134134
</data>
135+
<data name="ParameterNotUsed" xml:space="preserve">
136+
<value>The parameter is not used.</value>
137+
</data>
135138
<data name="PrivateConstructorStandardTextFirstPart" xml:space="preserve">
136139
<value>Prevents a default instance of the </value>
137140
</data>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.ru-RU.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<data name="NonPrivateConstructorStandardTextSecondPart" xml:space="preserve">
130130
<value />
131131
</data>
132+
<data name="ParameterNotUsed" xml:space="preserve">
133+
<value>Параметр не используется.</value>
134+
</data>
132135
<data name="PrivateConstructorStandardTextFirstPart" xml:space="preserve">
133136
<value>Предотвращает вызов конструктора по умолчанию для {0} </value>
134137
</data>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1625ElementDocumentationMustNotBeCopiedAndPasted.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ namespace StyleCop.Analyzers.DocumentationRules
66
using System;
77
using System.Collections.Generic;
88
using System.Collections.Immutable;
9+
using System.Globalization;
910
using System.Linq;
11+
using System.Resources;
1012
using System.Xml.Linq;
1113
using Helpers;
1214
using Helpers.ObjectPools;
@@ -67,7 +69,6 @@ internal class SA1625ElementDocumentationMustNotBeCopiedAndPasted : ElementDocum
6769
/// analyzer.
6870
/// </summary>
6971
public const string DiagnosticId = "SA1625";
70-
private const string ParameterNotUsed = "The parameter is not used.";
7172
private const string Title = "Element documentation must not be copied and pasted";
7273
private const string MessageFormat = "Element documentation must not be copied and pasted";
7374
private const string Description = "The Xml documentation for a C# element contains two or more identical entries, indicating that the documentation has been copied and pasted. This can sometimes indicate invalid or poorly written documentation.";
@@ -90,12 +91,15 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, IEnu
9091
{
9192
var objectPool = SharedPools.Default<HashSet<string>>();
9293
HashSet<string> documentationTexts = objectPool.Allocate();
94+
var settings = context.Options.GetStyleCopSettings(context.CancellationToken);
95+
var culture = new CultureInfo(settings.DocumentationRules.DocumentationCulture);
96+
var resourceManager = DocumentationResources.ResourceManager;
9397

9498
foreach (var documentationSyntax in syntaxList)
9599
{
96100
var documentation = XmlCommentHelper.GetText(documentationSyntax, true)?.Trim();
97101

98-
if (ShouldSkipElement(documentation))
102+
if (ShouldSkipElement(documentation, resourceManager.GetString(nameof(DocumentationResources.ParameterNotUsed), culture)))
99103
{
100104
continue;
101105
}
@@ -119,6 +123,9 @@ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext co
119123
{
120124
var objectPool = SharedPools.Default<HashSet<string>>();
121125
HashSet<string> documentationTexts = objectPool.Allocate();
126+
var settings = context.Options.GetStyleCopSettings(context.CancellationToken);
127+
var culture = new CultureInfo(settings.DocumentationRules.DocumentationCulture);
128+
var resourceManager = DocumentationResources.ResourceManager;
122129

123130
// Concatenate all XML node values
124131
var documentationElements = completeDocumentation.Nodes()
@@ -140,7 +147,7 @@ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext co
140147

141148
foreach (var documentation in documentationElements)
142149
{
143-
if (ShouldSkipElement(documentation))
150+
if (ShouldSkipElement(documentation, resourceManager.GetString(nameof(DocumentationResources.ParameterNotUsed), culture)))
144151
{
145152
continue;
146153
}
@@ -159,9 +166,9 @@ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext co
159166
objectPool.ClearAndFree(documentationTexts);
160167
}
161168

162-
private static bool ShouldSkipElement(string element)
169+
private static bool ShouldSkipElement(string element, string parameterNotUsed)
163170
{
164-
return string.IsNullOrWhiteSpace(element) || string.Equals(element, ParameterNotUsed, StringComparison.Ordinal);
171+
return string.IsNullOrWhiteSpace(element) || string.Equals(element, parameterNotUsed, StringComparison.Ordinal);
165172
}
166173
}
167174
}

0 commit comments

Comments
 (0)