File tree Expand file tree Collapse file tree
StyleCop.Analyzers.CodeFixes/MaintainabilityRules
StyleCop.Analyzers.Test/MaintainabilityRules Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,10 +68,17 @@ private static SyntaxNode GetReplacement(ParenthesizedExpressionSyntax oldNode)
6868 var trailingTrivia = oldNode . Expression . GetTrailingTrivia ( ) . AddRange ( oldNode . CloseParenToken . GetAllTrivia ( ) ) ;
6969
7070 // Workaround for Roslyn not handling elastic markers for directive trivia correctly.
71- var leadingSeparator = ( oldNode . Parent is DirectiveTriviaSyntax ) ? SyntaxFactory . Space : SyntaxFactory . ElasticMarker ;
71+ if ( ! leadingTrivia . Any ( ) )
72+ {
73+ var previousToken = oldNode . OpenParenToken . GetPreviousToken ( ) ;
74+ if ( TriviaHelper . IndexOfTrailingWhitespace ( previousToken . TrailingTrivia ) == - 1 )
75+ {
76+ leadingTrivia = SyntaxFactory . TriviaList ( SyntaxFactory . Space ) ;
77+ }
78+ }
7279
7380 return oldNode . Expression
74- . WithLeadingTrivia ( leadingTrivia . Any ( ) ? leadingTrivia : SyntaxFactory . TriviaList ( leadingSeparator ) )
81+ . WithLeadingTrivia ( leadingTrivia )
7582 . WithTrailingTrivia ( trailingTrivia . Any ( ) ? trailingTrivia : SyntaxFactory . TriviaList ( SyntaxFactory . ElasticMarker ) ) ;
7683 }
7784
Original file line number Diff line number Diff line change @@ -1418,6 +1418,9 @@ public static void Main(string[] args)
14181418
14191419#endif
14201420
1421+ #if (DEBUG)
1422+
1423+ #endif
14211424 }
14221425}
14231426" ;
@@ -1431,6 +1434,9 @@ public static void Main(string[] args)
14311434
14321435#endif
14331436
1437+ #if DEBUG
1438+
1439+ #endif
14341440 }
14351441}
14361442" ;
@@ -1439,6 +1445,9 @@ public static void Main(string[] args)
14391445 this . CSharpDiagnostic ( DiagnosticId ) . WithLocation ( 6 , 4 ) ,
14401446 this . CSharpDiagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 6 , 4 ) ,
14411447 this . CSharpDiagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 6 , 10 ) ,
1448+ this . CSharpDiagnostic ( DiagnosticId ) . WithLocation ( 10 , 5 ) ,
1449+ this . CSharpDiagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 10 , 5 ) ,
1450+ this . CSharpDiagnostic ( ParenthesesDiagnosticId ) . WithLocation ( 10 , 11 ) ,
14421451 } ;
14431452
14441453 await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
You can’t perform that action at this time.
0 commit comments