Skip to content

Commit 3dedce0

Browse files
vweijsterssharwell
authored andcommitted
Improved SA1501 codefix to allow for a single pass fixall
1 parent d29958f commit 3dedce0

6 files changed

Lines changed: 313 additions & 259 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/IndentationHelper.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ public static int GetIndentationSteps(IndentationSettings indentationSettings, S
5656
/// <returns>The number of steps that the token is indented.</returns>
5757
public static int GetIndentationSteps(IndentationSettings indentationSettings, SyntaxToken token)
5858
{
59-
return GetIndentationSteps(indentationSettings, token.SyntaxTree, token.LeadingTrivia);
59+
// If the token does not belong to a syntax tree, it is a modified token and it is assumed that
60+
// the caller makes sure that the token is the first token on a line.
61+
return token.SyntaxTree != null
62+
? GetIndentationSteps(indentationSettings, token.SyntaxTree, token.LeadingTrivia)
63+
: GetIndentationStepsUnchecked(indentationSettings, token.LeadingTrivia);
6064
}
6165

6266
/// <summary>
@@ -104,6 +108,11 @@ private static int GetIndentationSteps(IndentationSettings indentationSettings,
104108
return 0;
105109
}
106110

111+
return GetIndentationStepsUnchecked(indentationSettings, leadingTrivia);
112+
}
113+
114+
private static int GetIndentationStepsUnchecked(IndentationSettings indentationSettings, SyntaxTriviaList leadingTrivia)
115+
{
107116
var builder = StringBuilderPool.Allocate();
108117

109118
foreach (SyntaxTrivia trivia in leadingTrivia.Reverse())

0 commit comments

Comments
 (0)