@@ -32,6 +32,27 @@ internal UsesXunitForTestsFormattingRule(Options options)
32
32
_options = options ;
33
33
}
34
34
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
+
35
56
public async Task < Solution > ProcessAsync ( Document document , SyntaxNode syntaxNode , CancellationToken cancellationToken )
36
57
{
37
58
var root = syntaxNode as CompilationUnitSyntax ;
@@ -52,23 +73,6 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
52
73
53
74
foreach ( var usingSyntax in root . Usings )
54
75
{
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
-
72
76
var symbolInfo = semanticModel . GetSymbolInfo ( usingSyntax . Name ) ;
73
77
if ( symbolInfo . Symbol != null )
74
78
{
@@ -79,12 +83,12 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
79
83
}
80
84
else
81
85
{
82
- addUsing ( usingSyntax ) ;
86
+ newUsings . Add ( RemoveLeadingAndTrailingCompilerDirectives ( usingSyntax ) ) ;
83
87
}
84
88
}
85
89
else
86
90
{
87
- addUsing ( usingSyntax ) ;
91
+ newUsings . Add ( RemoveLeadingAndTrailingCompilerDirectives ( usingSyntax ) ) ;
88
92
}
89
93
}
90
94
0 commit comments