Skip to content

Commit 37a845a

Browse files
Change Span of PutFullAccessorOnOwnLine to be correct (#1661)
* Change Span of PutFullAccessorOnOwnLine to be correct Also fixes the application of the code fix * Fix diagnostic location for PutFullAccessorOnItsOwnLine rule and update tests --------- Co-authored-by: Josef Pihrt <josef@pihrt.net>
1 parent 8ea17dd commit 37a845a

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/Formatting.Analyzers/CSharp/AccessorListAnalyzer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ private static void AnalyzeAccessorList(SyntaxNodeAnalysisContext context)
5959
DiagnosticHelpers.ReportDiagnostic(
6060
context,
6161
DiagnosticRules.PutFullAccessorOnItsOwnLine,
62-
Location.Create(accessor.SyntaxTree, new TextSpan(accessor.SpanStart, 0)));
63-
64-
break;
62+
Location.Create(accessor.SyntaxTree, accessor.Span));
6563
}
6664

6765
token = accessor.Body?.CloseBraceToken ?? accessor.SemicolonToken;

src/Tests/Formatting.Analyzers.Tests/RCS0025PutFullAccessorOnItsOwnLineTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class C
2020
{
2121
private string _p;
2222
23-
public string P { [||]get { return _p; } set { _p = value; } }
23+
public string P { [|get { return _p; }|] [|set { _p = value; }|] }
2424
}
2525
", @"
2626
class C
@@ -46,7 +46,7 @@ class C
4646
4747
public string P
4848
{
49-
get { return _p; } [||]set { _p = value; }
49+
get { return _p; } [|set { _p = value; }|]
5050
}
5151
}
5252
", @"
@@ -71,7 +71,7 @@ class C
7171
{
7272
private string _p;
7373
74-
public string P { [||]get => _p; set => _p = value; }
74+
public string P { [|get => _p;|] [|set => _p = value;|] }
7575
}
7676
", @"
7777
class C
@@ -97,7 +97,7 @@ class C
9797
9898
public string P
9999
{
100-
get => _p; [||]set => _p = value;
100+
get => _p; [|set => _p = value;|]
101101
}
102102
}
103103
", @"
@@ -122,7 +122,7 @@ class C
122122
{
123123
private string _p;
124124
125-
public string P { [||]get { return _p; } }
125+
public string P { [|get { return _p; }|] }
126126
}
127127
", @"
128128
class C
@@ -145,7 +145,7 @@ class C
145145
{
146146
private string _p;
147147
148-
public string P { [||]get => _p; }
148+
public string P { [|get => _p;|] }
149149
}
150150
", @"
151151
class C

0 commit comments

Comments
 (0)