Skip to content

Commit e50ebd3

Browse files
author
Dirk Lemstra
committed
Fixed issue with properties that have an accessibility restriction.
1 parent 4755c66 commit e50ebd3

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1513UnitTests.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,93 @@ public int Do(int i)
826826
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
827827
}
828828

829+
/// <summary>
830+
/// Verifies that setters with an accessibility restriction should not report a warning.
831+
/// </summary>
832+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
833+
[Fact]
834+
public async Task TestSetterWithAccessibilityRestrictionAsync()
835+
{
836+
var testCode = @"
837+
public class TestClass
838+
{
839+
public int TestProtected
840+
{
841+
get
842+
{
843+
return 1;
844+
}
845+
protected set
846+
{
847+
}
848+
}
849+
850+
public int TestInternal
851+
{
852+
get
853+
{
854+
return 1;
855+
}
856+
internal set
857+
{
858+
}
859+
}
860+
861+
public int TestPrivate
862+
{
863+
get
864+
{
865+
return 1;
866+
}
867+
private set
868+
{
869+
}
870+
}
871+
872+
public int this[int i]
873+
{
874+
get
875+
{
876+
return 1;
877+
}
878+
protected set
879+
{
880+
}
881+
}
882+
}
883+
884+
public class TestClass2
885+
{
886+
public int this[int i]
887+
{
888+
get
889+
{
890+
return 1;
891+
}
892+
internal set
893+
{
894+
}
895+
}
896+
}
897+
898+
public class TestClass3
899+
{
900+
public int this[int i]
901+
{
902+
get
903+
{
904+
return 1;
905+
}
906+
private set
907+
{
908+
}
909+
}
910+
}
911+
";
912+
913+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
914+
}
915+
829916
/// <inheritdoc/>
830917
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
831918
{

StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1513ClosingBraceMustBeFollowedByBlankLine.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,15 @@ private void AnalyzeCloseBrace(SyntaxToken token)
277277
return;
278278
}
279279

280+
if ((nextToken.IsKind(SyntaxKind.PrivateKeyword)
281+
|| nextToken.IsKind(SyntaxKind.ProtectedKeyword)
282+
|| nextToken.IsKind(SyntaxKind.InternalKeyword))
283+
&& (nextToken.Parent is AccessorDeclarationSyntax))
284+
{
285+
// the close brace is followed by an accessor with an accessibility restriction.
286+
return;
287+
}
288+
280289
var parenthesizedExpressionSyntax = nextToken.Parent as ParenthesizedExpressionSyntax;
281290
if (parenthesizedExpressionSyntax?.CloseParenToken == nextToken)
282291
{

0 commit comments

Comments
 (0)