@@ -32,6 +32,27 @@ internal UsesXunitForTestsFormattingRule(Options options)
3232 _options = options ;
3333 }
3434
35+ private static UsingDirectiveSyntax RemoveLeadingAndTrailingCompilerDirectives ( UsingDirectiveSyntax usingSyntax )
36+ {
37+ UsingDirectiveSyntax usingDirectiveToUse = usingSyntax ;
38+ if ( usingDirectiveToUse . HasLeadingTrivia )
39+ {
40+ if ( usingDirectiveToUse . HasLeadingTrivia )
41+ {
42+ var newLeadingTrivia = RemoveCompilerDirectives ( usingDirectiveToUse . GetLeadingTrivia ( ) ) ;
43+ usingDirectiveToUse = usingDirectiveToUse . WithLeadingTrivia ( newLeadingTrivia ) ;
44+ }
45+ if ( usingDirectiveToUse . HasTrailingTrivia )
46+ {
47+ var newTrailingTrivia = RemoveCompilerDirectives ( usingDirectiveToUse . GetTrailingTrivia ( ) ) ;
48+ usingDirectiveToUse = usingDirectiveToUse . WithTrailingTrivia ( newTrailingTrivia ) ;
49+ }
50+ }
51+
52+ return usingDirectiveToUse ;
53+ }
54+
55+
3556 public async Task < Solution > ProcessAsync ( Document document , SyntaxNode syntaxNode , CancellationToken cancellationToken )
3657 {
3758 var root = syntaxNode as CompilationUnitSyntax ;
@@ -52,23 +73,6 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
5273
5374 foreach ( var usingSyntax in root . Usings )
5475 {
55- Action < UsingDirectiveSyntax > addUsing = ( UsingDirectiveSyntax newUsingSyntax ) =>
56- {
57- UsingDirectiveSyntax usingDirectiveToUse = newUsingSyntax ;
58- if ( usingDirectiveToUse . HasLeadingTrivia )
59- {
60- var newLeadingTrivia = RemoveCompilerDirectives ( usingDirectiveToUse . GetLeadingTrivia ( ) ) ;
61- usingDirectiveToUse = usingDirectiveToUse . WithLeadingTrivia ( newLeadingTrivia ) ;
62- }
63- if ( usingDirectiveToUse . HasTrailingTrivia )
64- {
65- var newTrailingTrivia = RemoveCompilerDirectives ( usingDirectiveToUse . GetTrailingTrivia ( ) ) ;
66- usingDirectiveToUse = usingDirectiveToUse . WithTrailingTrivia ( newTrailingTrivia ) ;
67- }
68-
69- newUsings . Add ( usingDirectiveToUse ) ;
70- } ;
71-
7276 var symbolInfo = semanticModel . GetSymbolInfo ( usingSyntax . Name ) ;
7377 if ( symbolInfo . Symbol != null )
7478 {
@@ -79,12 +83,12 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
7983 }
8084 else
8185 {
82- addUsing ( usingSyntax ) ;
86+ newUsings . Add ( RemoveLeadingAndTrailingCompilerDirectives ( usingSyntax ) ) ;
8387 }
8488 }
8589 else
8690 {
87- addUsing ( usingSyntax ) ;
91+ newUsings . Add ( RemoveLeadingAndTrailingCompilerDirectives ( usingSyntax ) ) ;
8892 }
8993 }
9094
0 commit comments