Skip to content

Commit

Permalink
Fix T0016 FP: Do not raise after single-line property (#9279)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-mikula-sonarsource committed May 15, 2024
1 parent 44cdd65 commit fab30c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void ValidatePossibleSingleLineMember(SonarSyntaxNodeReportingContext co
{
var firstToken = context.Node.GetFirstToken();
if (firstToken.Line() != context.Node.GetLastToken().Line()
|| firstToken.GetPreviousToken().IsKind(SyntaxKind.CloseBraceToken)
|| IsStandaloneCloseBrace(firstToken.GetPreviousToken())
|| PreviousDeclarationKind() != context.Node.Kind())
{
ValidateSeparatedMember(context);
Expand All @@ -64,6 +64,9 @@ private void ValidatePossibleSingleLineMember(SonarSyntaxNodeReportingContext co
context.Node.Parent.ChildNodes().TakeWhile(x => x != context.Node).LastOrDefault() is { } preceding
? preceding.Kind()
: SyntaxKind.None;

static bool IsStandaloneCloseBrace(SyntaxToken token) =>
token.IsKind(SyntaxKind.CloseBraceToken) && token.Line() != token.GetPreviousToken().Line();
}

private void ValidateSeparatedMember(SonarSyntaxNodeReportingContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ private enum Enum3 { None, Any, All }

public object Property1 { get; } = 42;
public object Property2 => 42;
public object Property3 { get => 42; }
public object Property3 => 43;
public object Property4 { get => 42; }
public object Property5 { get; set; }
public object Property6 { get; set; }

public object this[int index] => 42;
public object this[bool value] => 42;
Expand Down

0 comments on commit fab30c6

Please sign in to comment.