@@ -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 ;
@@ -62,21 +83,13 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
6283 }
6384 else
6485 {
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 ) ) ;
7887 }
7988 }
89+ else
90+ {
91+ newUsings . Add ( RemoveLeadingAndTrailingCompilerDirectives ( usingSyntax ) ) ;
92+ }
8093 }
8194
8295 if ( ! needsChanges )
@@ -86,6 +99,7 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
8699
87100 TransformationTracker transformationTracker = new TransformationTracker ( ) ;
88101 RemoveTestClassAttributes ( root , semanticModel , transformationTracker ) ;
102+ RemoveContractsRequiredAttributes ( root , semanticModel , transformationTracker ) ;
89103 ChangeTestMethodAttributesToFact ( root , semanticModel , transformationTracker ) ;
90104 ChangeAssertCalls ( root , semanticModel , transformationTracker ) ;
91105 root = transformationTracker . TransformRoot ( root ) ;
@@ -115,7 +129,17 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
115129 return document . WithSyntaxRoot ( root ) . Project . Solution ;
116130 }
117131
132+ private void RemoveContractsRequiredAttributes ( CompilationUnitSyntax root , SemanticModel semanticModel , TransformationTracker transformationTracker )
133+ {
134+ RemoveTestAttributes ( root , semanticModel , transformationTracker , "ContractsRequiredAttribute" ) ;
135+ }
136+
118137 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 )
119143 {
120144 List < AttributeSyntax > nodesToRemove = new List < AttributeSyntax > ( ) ;
121145
@@ -127,7 +151,7 @@ private void RemoveTestClassAttributes(CompilationUnitSyntax root, SemanticModel
127151 if ( typeInfo . Type != null )
128152 {
129153 string attributeTypeDocID = typeInfo . Type . GetDocumentationCommentId ( ) ;
130- if ( IsTestNamespaceType ( attributeTypeDocID , "TestClassAttribute" ) )
154+ if ( IsTestNamespaceType ( attributeTypeDocID , attributeName ) )
131155 {
132156 return true ;
133157 }
@@ -156,6 +180,7 @@ private void RemoveTestClassAttributes(CompilationUnitSyntax root, SemanticModel
156180 return transformationRoot ;
157181 } ) ;
158182 }
183+
159184 private void ChangeTestMethodAttributesToFact ( CompilationUnitSyntax root , SemanticModel semanticModel , TransformationTracker transformationTracker )
160185 {
161186 List < AttributeSyntax > nodesToReplace = new List < AttributeSyntax > ( ) ;
0 commit comments