Skip to content

Commit c3afe7b

Browse files
committed
Removed unreachable code and added some comments.
1 parent 2a94de8 commit c3afe7b

2 files changed

Lines changed: 5 additions & 14 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1636UnitTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ namespace Bar
192192
await this.VerifyCSharpDiagnosticAsync(new[] { testCode1, testCode2, testCode3 }, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
193193
}
194194

195-
/// <inheritdoc/>
196195
/// <summary>
197196
/// Verifies that a file header with an incorrect copyright text the fix only replaces the text.
198197
/// </summary>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/FileHeaderCodeFixProvider.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,6 @@ private static SyntaxNode ReplaceHeader(Document document, SyntaxNode root, Styl
140140
}
141141
}
142142

143-
if (isMalformedHeader)
144-
{
145-
copyrightTriviaIndex = null;
146-
}
147-
148143
// Remove copyright lines in reverse order
149144
removalList.Reverse();
150145
foreach (var triviaLine in removalList)
@@ -155,23 +150,20 @@ private static SyntaxNode ReplaceHeader(Document document, SyntaxNode root, Styl
155150
string newLineText = document.Project.Solution.Workspace.Options.GetOption(FormattingOptions.NewLine, LanguageNames.CSharp);
156151

157152
var newHeaderTrivia = CreateNewHeader(document.Name, settings, newLineText);
158-
if (copyrightTriviaIndex.HasValue)
153+
if (!isMalformedHeader && copyrightTriviaIndex.HasValue)
159154
{
160-
if (inCopyright)
161-
{
162-
newHeaderTrivia = newHeaderTrivia.Add(SyntaxFactory.CarriageReturnLineFeed);
163-
}
164-
165-
trivia = trivia.ReplaceRange(trivia[copyrightTriviaIndex.Value], newHeaderTrivia);
166-
return root.WithLeadingTrivia(trivia);
155+
// Replace copyright element in place.
156+
return root.WithLeadingTrivia(trivia.ReplaceRange(trivia[copyrightTriviaIndex.Value], newHeaderTrivia));
167157
}
168158
else
169159
{
160+
// Add blank line if we don't already have comments at top of file.
170161
if ((trivia.Count == 0) || (trivia[0].Kind() != SyntaxKind.SingleLineCommentTrivia))
171162
{
172163
newHeaderTrivia = newHeaderTrivia.Add(SyntaxFactory.CarriageReturnLineFeed);
173164
}
174165

166+
// Insert header at top of the file.
175167
return root.WithLeadingTrivia(newHeaderTrivia.Add(SyntaxFactory.CarriageReturnLineFeed).AddRange(trivia));
176168
}
177169
}

0 commit comments

Comments
 (0)