Skip to content

Commit 7eb2a1a

Browse files
committed
Add ECS0006 - Item #6
Related to BillWagner/EffectiveCSharpAnalyzers#6
2 parents 978e492 + e226cde commit 7eb2a1a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Diff for: src/EffectiveCSharp.Analyzers/AvoidStringlyTypedApisAnalyzer.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
[DiagnosticAnalyzer(LanguageNames.CSharp)]
88
public class AvoidStringlyTypedApisAnalyzer : DiagnosticAnalyzer
99
{
10-
internal const string DiagnosticId = DiagnosticIds.AvoidStringlyTypedApis;
10+
private const string DiagnosticId = DiagnosticIds.AvoidStringlyTypedApis;
1111
private const string Title = "Avoid stringly-typed APIs";
1212
private const string MessageFormat = "Use 'nameof({0})' instead of the string literal \"{0}\"";
13-
private const string Description = "Replace string literals representing member names with the nameof operator to ensure type safety.";
13+
14+
private const string Description =
15+
"Replace string literals representing member names with the nameof operator to ensure type safety.";
16+
1417
private const string Category = "Refactoring";
1518

1619
private static readonly DiagnosticDescriptor Rule = new(
@@ -21,7 +24,8 @@ public class AvoidStringlyTypedApisAnalyzer : DiagnosticAnalyzer
2124
DiagnosticSeverity.Warning,
2225
isEnabledByDefault: true,
2326
description: Description,
24-
helpLinkUri: $"https://github.com/rjmurillo/EffectiveCSharp.Analyzers{ThisAssembly.GitCommitId}/docs/{DiagnosticId}.md");
27+
helpLinkUri:
28+
$"https://github.com/rjmurillo/EffectiveCSharp.Analyzers{ThisAssembly.GitCommitId}/docs/{DiagnosticId}.md");
2529

2630
/// <inheritdoc/>
2731
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);
@@ -45,7 +49,8 @@ private static void AnalyzeLiteralExpression(SyntaxNodeAnalysisContext context)
4549

4650
SemanticModel semanticModel = context.SemanticModel;
4751

48-
if (containingClass != null && semanticModel.GetDeclaredSymbol(containingClass, context.CancellationToken) is { } containingTypeSymbol)
52+
if (containingClass != null
53+
&& semanticModel.GetDeclaredSymbol(containingClass, context.CancellationToken) is { } containingTypeSymbol)
4954
{
5055
IEnumerable<string> memberNames = containingTypeSymbol.GetMembers().Select(member => member.Name);
5156

@@ -56,7 +61,8 @@ private static void AnalyzeLiteralExpression(SyntaxNodeAnalysisContext context)
5661
}
5762
}
5863

59-
if (containingMethod != null && semanticModel.GetDeclaredSymbol(containingMethod, context.CancellationToken) is { } methodSymbol)
64+
if (containingMethod != null
65+
&& semanticModel.GetDeclaredSymbol(containingMethod, context.CancellationToken) is { } methodSymbol)
6066
{
6167
IEnumerable<string> parameterNames = methodSymbol.Parameters.Select(parameter => parameter.Name);
6268

0 commit comments

Comments
 (0)