Skip to content

Commit 932e6e9

Browse files
committed
Merge pull request #1846 from sharwell/fix-1778
Improve messaging for SA1205
2 parents d6c83c4 + 2cbba62 commit 932e6e9

2 files changed

Lines changed: 7 additions & 14 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1205PartialElementsMustDeclareAccess.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ namespace StyleCop.Analyzers.OrderingRules
1212
using Microsoft.CodeAnalysis.Diagnostics;
1313

1414
/// <summary>
15-
/// The partial element does not have an access modifier defined. StyleCop may not be able to determine the correct
16-
/// placement of the elements in the file. Please declare an access modifier for all partial elements.
15+
/// The partial element does not have an access modifier defined.
1716
/// </summary>
1817
/// <remarks>
1918
/// <para>A violation of this rule occurs when the partial elements does not have an access modifier defined.</para>
@@ -27,7 +26,7 @@ internal class SA1205PartialElementsMustDeclareAccess : DiagnosticAnalyzer
2726
public const string DiagnosticId = "SA1205";
2827
private const string Title = "Partial elements must declare access";
2928
private const string MessageFormat = "Partial elements must declare an access modifier";
30-
private const string Description = "The partial element does not have an access modifier defined. StyleCop may not be able to determine the correct placement of the elements in the file. Please declare an access modifier for all partial elements.";
29+
private const string Description = "The partial element does not have an access modifier defined.";
3130
private const string HelpLink = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1205.md";
3231

3332
private static readonly DiagnosticDescriptor Descriptor =
@@ -58,19 +57,14 @@ private static void HandleTypeDeclaration(SyntaxNodeAnalysisContext context)
5857
{
5958
var typeDeclarationNode = (TypeDeclarationSyntax)context.Node;
6059

61-
if (ContainsModifier(typeDeclarationNode.Modifiers, SyntaxKind.PartialKeyword))
60+
if (typeDeclarationNode.Modifiers.Any(SyntaxKind.PartialKeyword))
6261
{
63-
if (!ContainsModifier(typeDeclarationNode.Modifiers, SyntaxKind.PublicKeyword) &&
64-
!ContainsModifier(typeDeclarationNode.Modifiers, SyntaxKind.InternalKeyword))
62+
if (!typeDeclarationNode.Modifiers.Any(SyntaxKind.PublicKeyword)
63+
&& !typeDeclarationNode.Modifiers.Any(SyntaxKind.InternalKeyword))
6564
{
6665
context.ReportDiagnostic(Diagnostic.Create(Descriptor, typeDeclarationNode.Identifier.GetLocation()));
6766
}
6867
}
6968
}
70-
71-
private static bool ContainsModifier(SyntaxTokenList modifiers, SyntaxKind expectedKeyword)
72-
{
73-
return modifiers.Any(modifier => modifier.Kind() == expectedKeyword);
74-
}
7569
}
7670
}

documentation/SA1205.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717

1818
## Cause
1919

20-
The partial element does not have an access modifier defined. StyleCop may not be able to determine the correct
21-
placement of the elements in the file. Please declare an access modifier for all partial elements.
20+
The partial element does not have an access modifier defined.
2221

2322
## Rule description
2423

2524
A violation of this rule occurs when the partial elements does not have an access modifier defined.
2625

2726
## How to fix violations
2827

29-
To fix an instance of this violation, specify an acess modifier for the partial element.
28+
To fix an instance of this violation, specify an access modifier for the partial element.
3029

3130
## How to suppress violations
3231

0 commit comments

Comments
 (0)