Skip to content

Commit 2df467c

Browse files
authored
Merge pull request #1 from SanjayGuntur/master
Port CodeCleanup bug fixes from CodePlex
2 parents 9c98a78 + be4a85e commit 2df467c

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/StyleCop.ReSharper/CodeCleanup/Rules/LayoutRules.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ private static void CommentsMustBePreceededByBlankLine(ITreeNode node)
363363
continue;
364364
}
365365

366+
if (siblingMinus3 is ISwitchLabelStatement)
367+
{
368+
// if we're the start of a switch block then don't insert a new line.
369+
continue;
370+
}
371+
366372
if (siblingMinus3Token != null && siblingMinus3Token.GetTokenType() == CSharpTokenType.LBRACE)
367373
{
368374
// if we're the start of a code block then don't insert a new line.
@@ -423,7 +429,7 @@ private static void CommentsMustNotBeFollowedByBlankLine(ITreeNode node)
423429
{
424430
ITokenNode nextNextNextToken = Utils.GetFirstNonWhitespaceTokenToRight(nextNextToken);
425431

426-
if (nextNextToken.IsNewLine() && !(nextNextNextToken is ICommentNode))
432+
if (nextNextToken.IsNewLine() && !(nextNextNextToken is ICommentNode) && !Utils.IsCommentInFileHeader(currentNode))
427433
{
428434
ITreeNode rightNode = currentNode.FindFormattingRangeToRight();
429435
Utils.RemoveNewLineBefore(rightNode);

src/StyleCop.ReSharper/CodeCleanup/Rules/ReadabilityRules.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static void RemoveEmptyComments(ITreeNode node)
155155
ICommentNode commentNode = currentNode as ICommentNode;
156156
if (commentNode != null && !(commentNode is IDocCommentNode))
157157
{
158-
if (commentNode.CommentText.Trim() == string.Empty)
158+
if (commentNode.CommentText.Trim() == string.Empty && !Utils.IsCommentInFileHeader(currentNode))
159159
{
160160
ITokenNode leftToken = Utils.GetFirstNewLineTokenToLeft((ITokenNode)currentNode);
161161

src/StyleCop.ReSharper/Core/Utils.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,24 @@ public static ITreeNode InsertWhitespaceAfter(ITreeNode currentNode, int count)
14581458
return leafElement;
14591459
}
14601460

1461+
public static bool IsCommentInFileHeader(ITreeNode comment)
1462+
{
1463+
for (ITreeNode currentNode = comment; currentNode != null; currentNode = currentNode.PrevSibling)
1464+
{
1465+
if (currentNode is ICommentNode || currentNode is IWhitespaceNode || currentNode is IPreprocessorDirective)
1466+
{
1467+
continue;
1468+
}
1469+
1470+
if (currentNode.NodeType != null)
1471+
{
1472+
return false;
1473+
}
1474+
}
1475+
1476+
return true;
1477+
}
1478+
14611479
/// <summary>
14621480
/// Indicates whether the type of the constructor passed in is a struct.
14631481
/// </summary>

0 commit comments

Comments
 (0)