@@ -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 ;
@@ -62,21 +83,13 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
62
83
}
63
84
else
64
85
{
65
- UsingDirectiveSyntax usingDirectiveToUse = usingSyntax ;
66
- if ( usingDirectiveToUse . HasLeadingTrivia )
67
- {
68
- var newLeadingTrivia = RemoveCompilerDirectives ( usingDirectiveToUse . GetLeadingTrivia ( ) ) ;
69
- usingDirectiveToUse = usingDirectiveToUse . WithLeadingTrivia ( newLeadingTrivia ) ;
70
- }
71
- if ( usingDirectiveToUse . HasTrailingTrivia )
72
- {
73
- var newTrailingTrivia = RemoveCompilerDirectives ( usingDirectiveToUse . GetTrailingTrivia ( ) ) ;
74
- usingDirectiveToUse = usingDirectiveToUse . WithTrailingTrivia ( newTrailingTrivia ) ;
75
- }
76
-
77
- newUsings . Add ( usingDirectiveToUse ) ;
86
+ newUsings . Add ( RemoveLeadingAndTrailingCompilerDirectives ( usingSyntax ) ) ;
78
87
}
79
88
}
89
+ else
90
+ {
91
+ newUsings . Add ( RemoveLeadingAndTrailingCompilerDirectives ( usingSyntax ) ) ;
92
+ }
80
93
}
81
94
82
95
if ( ! needsChanges )
@@ -86,6 +99,7 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
86
99
87
100
TransformationTracker transformationTracker = new TransformationTracker ( ) ;
88
101
RemoveTestClassAttributes ( root , semanticModel , transformationTracker ) ;
102
+ RemoveContractsRequiredAttributes ( root , semanticModel , transformationTracker ) ;
89
103
ChangeTestMethodAttributesToFact ( root , semanticModel , transformationTracker ) ;
90
104
ChangeAssertCalls ( root , semanticModel , transformationTracker ) ;
91
105
root = transformationTracker . TransformRoot ( root ) ;
@@ -115,7 +129,17 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
115
129
return document . WithSyntaxRoot ( root ) . Project . Solution ;
116
130
}
117
131
132
+ private void RemoveContractsRequiredAttributes ( CompilationUnitSyntax root , SemanticModel semanticModel , TransformationTracker transformationTracker )
133
+ {
134
+ RemoveTestAttributes ( root , semanticModel , transformationTracker , "ContractsRequiredAttribute" ) ;
135
+ }
136
+
118
137
private void RemoveTestClassAttributes ( CompilationUnitSyntax root , SemanticModel semanticModel , TransformationTracker transformationTracker )
138
+ {
139
+ RemoveTestAttributes ( root , semanticModel , transformationTracker , "TestClassAttribute" ) ;
140
+ }
141
+
142
+ private void RemoveTestAttributes ( CompilationUnitSyntax root , SemanticModel semanticModel , TransformationTracker transformationTracker , string attributeName )
119
143
{
120
144
List < AttributeSyntax > nodesToRemove = new List < AttributeSyntax > ( ) ;
121
145
@@ -127,7 +151,7 @@ private void RemoveTestClassAttributes(CompilationUnitSyntax root, SemanticModel
127
151
if ( typeInfo . Type != null )
128
152
{
129
153
string attributeTypeDocID = typeInfo . Type . GetDocumentationCommentId ( ) ;
130
- if ( IsTestNamespaceType ( attributeTypeDocID , "TestClassAttribute" ) )
154
+ if ( IsTestNamespaceType ( attributeTypeDocID , attributeName ) )
131
155
{
132
156
return true ;
133
157
}
@@ -156,6 +180,7 @@ private void RemoveTestClassAttributes(CompilationUnitSyntax root, SemanticModel
156
180
return transformationRoot ;
157
181
} ) ;
158
182
}
183
+
159
184
private void ChangeTestMethodAttributesToFact ( CompilationUnitSyntax root , SemanticModel semanticModel , TransformationTracker transformationTracker )
160
185
{
161
186
List < AttributeSyntax > nodesToReplace = new List < AttributeSyntax > ( ) ;
0 commit comments