Skip to content

Commit 8ef89ea

Browse files
authored
Merge pull request #2946 from vweijsters/cleanup2
Code cleanup attempt #2
2 parents 5456aef + f9ecfd7 commit 8ef89ea

110 files changed

Lines changed: 306 additions & 405 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/FileHeaderCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ private static SyntaxNode ReplaceHeader(Document document, SyntaxNode root, Styl
316316
// Does the copyright element have leading whitespace? If so remove it.
317317
if ((copyrightTriviaIndex.Value > 0) && trivia[copyrightTriviaIndex.Value - 1].IsKind(SyntaxKind.WhitespaceTrivia))
318318
{
319-
copyrightTriviaIndex = copyrightTriviaIndex - 1;
319+
copyrightTriviaIndex--;
320320
trivia = trivia.RemoveAt(copyrightTriviaIndex.Value);
321321
}
322322

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/InheritdocCodeFixProvider.cs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,36 +90,36 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
9090
context.RegisterCodeFix(
9191
CodeAction.Create(
9292
DocumentationResources.InheritdocCodeFix,
93-
cancellationToken => GetTransformedDocumentAsync(context.Document, diagnostic, root, identifierToken, cancellationToken),
93+
cancellationToken => GetTransformedDocumentAsync(context.Document, root, identifierToken, cancellationToken),
9494
nameof(InheritdocCodeFixProvider)),
9595
diagnostic);
9696
}
9797
}
9898

99-
private static async Task<Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, SyntaxNode root, SyntaxToken identifierToken, CancellationToken cancellationToken)
99+
private static async Task<Document> GetTransformedDocumentAsync(Document document, SyntaxNode root, SyntaxToken identifierToken, CancellationToken cancellationToken)
100100
{
101101
SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
102102
switch (identifierToken.Parent.Kind())
103103
{
104104
case SyntaxKind.PropertyDeclaration:
105105
case SyntaxKind.EventDeclaration:
106-
return GetTransformedDocumentForBasePropertyDeclaration(document, diagnostic, root, semanticModel, (BasePropertyDeclarationSyntax)identifierToken.Parent, cancellationToken);
106+
return GetTransformedDocumentForBasePropertyDeclaration(document, root, semanticModel, (BasePropertyDeclarationSyntax)identifierToken.Parent, cancellationToken);
107107

108108
case SyntaxKind.MethodDeclaration:
109-
return GetTransformedDocumentForMethodDeclaration(document, diagnostic, root, semanticModel, (MethodDeclarationSyntax)identifierToken.Parent, cancellationToken);
109+
return GetTransformedDocumentForMethodDeclaration(document, root, semanticModel, (MethodDeclarationSyntax)identifierToken.Parent, cancellationToken);
110110

111111
case SyntaxKind.VariableDeclarator:
112-
return GetTransformedDocumentForEventFieldDeclaration(document, diagnostic, root, semanticModel, (EventFieldDeclarationSyntax)identifierToken.Parent.Parent.Parent, cancellationToken);
112+
return GetTransformedDocumentForEventFieldDeclaration(document, root, semanticModel, (EventFieldDeclarationSyntax)identifierToken.Parent.Parent.Parent, cancellationToken);
113113

114114
case SyntaxKind.IndexerDeclaration:
115-
return GetTransformedDocumentForIndexerDeclaration(document, diagnostic, root, semanticModel, (IndexerDeclarationSyntax)identifierToken.Parent, cancellationToken);
115+
return GetTransformedDocumentForIndexerDeclaration(document, root, semanticModel, (IndexerDeclarationSyntax)identifierToken.Parent, cancellationToken);
116116

117117
default:
118118
return document;
119119
}
120120
}
121121

122-
private static Document GetTransformedDocumentForBasePropertyDeclaration(Document document, Diagnostic diagnostic, SyntaxNode root, SemanticModel semanticModel, BasePropertyDeclarationSyntax basePropertyDeclaration, CancellationToken cancellationToken)
122+
private static Document GetTransformedDocumentForBasePropertyDeclaration(Document document, SyntaxNode root, SemanticModel semanticModel, BasePropertyDeclarationSyntax basePropertyDeclaration, CancellationToken cancellationToken)
123123
{
124124
if (basePropertyDeclaration.ExplicitInterfaceSpecifier == null && !basePropertyDeclaration.Modifiers.Any(SyntaxKind.OverrideKeyword))
125125
{
@@ -130,10 +130,10 @@ private static Document GetTransformedDocumentForBasePropertyDeclaration(Documen
130130
}
131131
}
132132

133-
return InsertInheritdocComment(document, diagnostic, root, basePropertyDeclaration, cancellationToken);
133+
return InsertInheritdocComment(document, root, basePropertyDeclaration, cancellationToken);
134134
}
135135

136-
private static Document GetTransformedDocumentForMethodDeclaration(Document document, Diagnostic diagnostic, SyntaxNode root, SemanticModel semanticModel, MethodDeclarationSyntax methodDeclaration, CancellationToken cancellationToken)
136+
private static Document GetTransformedDocumentForMethodDeclaration(Document document, SyntaxNode root, SemanticModel semanticModel, MethodDeclarationSyntax methodDeclaration, CancellationToken cancellationToken)
137137
{
138138
if (methodDeclaration.ExplicitInterfaceSpecifier == null && !methodDeclaration.Modifiers.Any(SyntaxKind.OverrideKeyword))
139139
{
@@ -144,10 +144,10 @@ private static Document GetTransformedDocumentForMethodDeclaration(Document docu
144144
}
145145
}
146146

147-
return InsertInheritdocComment(document, diagnostic, root, methodDeclaration, cancellationToken);
147+
return InsertInheritdocComment(document, root, methodDeclaration, cancellationToken);
148148
}
149149

150-
private static Document GetTransformedDocumentForEventFieldDeclaration(Document document, Diagnostic diagnostic, SyntaxNode root, SemanticModel semanticModel, EventFieldDeclarationSyntax eventFieldDeclaration, CancellationToken cancellationToken)
150+
private static Document GetTransformedDocumentForEventFieldDeclaration(Document document, SyntaxNode root, SemanticModel semanticModel, EventFieldDeclarationSyntax eventFieldDeclaration, CancellationToken cancellationToken)
151151
{
152152
if (!eventFieldDeclaration.Modifiers.Any(SyntaxKind.OverrideKeyword))
153153
{
@@ -164,10 +164,10 @@ private static Document GetTransformedDocumentForEventFieldDeclaration(Document
164164
}
165165
}
166166

167-
return InsertInheritdocComment(document, diagnostic, root, eventFieldDeclaration, cancellationToken);
167+
return InsertInheritdocComment(document, root, eventFieldDeclaration, cancellationToken);
168168
}
169169

170-
private static Document GetTransformedDocumentForIndexerDeclaration(Document document, Diagnostic diagnostic, SyntaxNode root, SemanticModel semanticModel, IndexerDeclarationSyntax indexerDeclaration, CancellationToken cancellationToken)
170+
private static Document GetTransformedDocumentForIndexerDeclaration(Document document, SyntaxNode root, SemanticModel semanticModel, IndexerDeclarationSyntax indexerDeclaration, CancellationToken cancellationToken)
171171
{
172172
if (indexerDeclaration.ExplicitInterfaceSpecifier == null && !indexerDeclaration.Modifiers.Any(SyntaxKind.OverrideKeyword))
173173
{
@@ -178,11 +178,14 @@ private static Document GetTransformedDocumentForIndexerDeclaration(Document doc
178178
}
179179
}
180180

181-
return InsertInheritdocComment(document, diagnostic, root, indexerDeclaration, cancellationToken);
181+
return InsertInheritdocComment(document, root, indexerDeclaration, cancellationToken);
182182
}
183183

184-
private static Document InsertInheritdocComment(Document document, Diagnostic diagnostic, SyntaxNode root, SyntaxNode syntaxNode, CancellationToken cancellationToken)
184+
private static Document InsertInheritdocComment(Document document, SyntaxNode root, SyntaxNode syntaxNode, CancellationToken cancellationToken)
185185
{
186+
// Currently unused
187+
_ = cancellationToken;
188+
186189
SyntaxTriviaList leadingTrivia = syntaxNode.GetLeadingTrivia();
187190
int insertionIndex = leadingTrivia.Count;
188191
while (insertionIndex > 0 && !leadingTrivia[insertionIndex - 1].HasBuiltinEndLine())

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1600CodeFixProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
5959
context.RegisterCodeFix(
6060
CodeAction.Create(
6161
DocumentationResources.ConstructorDocumentationCodeFix,
62-
cancellationToken => GetConstructorOrDestructorDocumentationTransformedDocumentAsync(context.Document, diagnostic, root, (BaseMethodDeclarationSyntax)identifierToken.Parent, cancellationToken),
62+
cancellationToken => GetConstructorOrDestructorDocumentationTransformedDocumentAsync(context.Document, root, (BaseMethodDeclarationSyntax)identifierToken.Parent, cancellationToken),
6363
nameof(SA1600CodeFixProvider)),
6464
diagnostic);
6565
break;
@@ -72,7 +72,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
7272
context.RegisterCodeFix(
7373
CodeAction.Create(
7474
DocumentationResources.MethodDocumentationCodeFix,
75-
cancellationToken => GetMethodDocumentationTransformedDocumentAsync(context.Document, diagnostic, root, semanticModel, (MethodDeclarationSyntax)identifierToken.Parent, cancellationToken),
75+
cancellationToken => GetMethodDocumentationTransformedDocumentAsync(context.Document, root, semanticModel, (MethodDeclarationSyntax)identifierToken.Parent, cancellationToken),
7676
nameof(SA1600CodeFixProvider)),
7777
diagnostic);
7878
}
@@ -98,7 +98,7 @@ private static bool IsCoveredByInheritDoc(SemanticModel semanticModel, MethodDec
9898
return (declaredSymbol != null) && NamedTypeHelpers.IsImplementingAnInterfaceMember(declaredSymbol);
9999
}
100100

101-
private static Task<Document> GetConstructorOrDestructorDocumentationTransformedDocumentAsync(Document document, Diagnostic diagnostic, SyntaxNode root, BaseMethodDeclarationSyntax declaration, CancellationToken cancellationToken)
101+
private static Task<Document> GetConstructorOrDestructorDocumentationTransformedDocumentAsync(Document document, SyntaxNode root, BaseMethodDeclarationSyntax declaration, CancellationToken cancellationToken)
102102
{
103103
SyntaxTriviaList leadingTrivia = declaration.GetLeadingTrivia();
104104
int insertionIndex = GetInsertionIndex(ref leadingTrivia);
@@ -136,7 +136,7 @@ private static Task<Document> GetConstructorOrDestructorDocumentationTransformed
136136
return Task.FromResult(document.WithSyntaxRoot(root.ReplaceNode(declaration, newElement)));
137137
}
138138

139-
private static Task<Document> GetMethodDocumentationTransformedDocumentAsync(Document document, Diagnostic diagnostic, SyntaxNode root, SemanticModel semanticModel, MethodDeclarationSyntax methodDeclaration, CancellationToken cancellationToken)
139+
private static Task<Document> GetMethodDocumentationTransformedDocumentAsync(Document document, SyntaxNode root, SemanticModel semanticModel, MethodDeclarationSyntax methodDeclaration, CancellationToken cancellationToken)
140140
{
141141
SyntaxTriviaList leadingTrivia = methodDeclaration.GetLeadingTrivia();
142142
int insertionIndex = GetInsertionIndex(ref leadingTrivia);

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1609SA1610CodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private bool TryRemoveSummaryPrefix(ref SyntaxList<XmlNodeSyntax> summaryContent
174174
}
175175

176176
// Find the token containing the prefix, such as "Gets or sets "
177-
SyntaxToken prefixToken = default(SyntaxToken);
177+
SyntaxToken prefixToken = default;
178178
foreach (SyntaxToken textToken in firstText.TextTokens)
179179
{
180180
if (textToken.IsMissing)

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1626CodeFixProvider.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
5353

5454
private static async Task<Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
5555
{
56-
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
5756
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
5857

5958
TextChange textChange = new TextChange(new TextSpan(diagnostic.Location.SourceSpan.Start, 1), string.Empty);

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1642SA1643CodeFixProvider.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private static Task<Document> GetTransformedDocumentAsync(Document document, Syn
147147

148148
string trailingString = string.Empty;
149149

150-
var newContent = RemoveMalformattedStandardText(node.Content, typeDeclaration.Identifier, standardText[0], standardText[1], ref trailingString);
150+
var newContent = RemoveMalformattedStandardText(node.Content, standardText[0], standardText[1], ref trailingString);
151151

152152
if (newContent.Count == 1 && newContent[0] is XmlTextSyntax xmlText)
153153
{
@@ -174,8 +174,6 @@ private static Task<Document> GetTransformedDocumentAsync(Document document, Syn
174174
private static Task<Document> GetTransformedDocumentAsync(Document document, SyntaxNode root, XmlEmptyElementSyntax node)
175175
{
176176
var typeDeclaration = node.FirstAncestorOrSelf<BaseTypeDeclarationSyntax>();
177-
var declarationSyntax = node.FirstAncestorOrSelf<BaseMethodDeclarationSyntax>();
178-
bool isStruct = typeDeclaration.IsKind(SyntaxKind.StructDeclaration);
179177

180178
TypeParameterListSyntax typeParameterList;
181179
if (typeDeclaration is ClassDeclarationSyntax classDeclaration)
@@ -194,7 +192,7 @@ private static Task<Document> GetTransformedDocumentAsync(Document document, Syn
194192
return Task.FromResult(newDocument);
195193
}
196194

197-
private static SyntaxList<XmlNodeSyntax> RemoveMalformattedStandardText(SyntaxList<XmlNodeSyntax> content, SyntaxToken identifier, string preText, string postText, ref string trailingString)
195+
private static SyntaxList<XmlNodeSyntax> RemoveMalformattedStandardText(SyntaxList<XmlNodeSyntax> content, string preText, string postText, ref string trailingString)
198196
{
199197
var regex = new Regex(@"^\s*" + Regex.Escape(preText) + "[^ ]+" + Regex.Escape(postText));
200198
var item = content.OfType<XmlTextSyntax>().FirstOrDefault();

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/FormattingHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static SyntaxTrivia WithoutFormatting(this SyntaxTrivia trivia)
9292
}
9393
}
9494

95-
return WithoutFormattingImpl(trivia);
95+
return WithoutFormattingImpl(result);
9696
}
9797

9898
/// <summary>

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/RenameHelper.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ public static SyntaxNode GetParentDeclaration(SyntaxToken token)
162162
return parent;
163163

164164
default:
165-
var declarationParent = parent as MemberDeclarationSyntax;
166-
if (declarationParent != null)
165+
if (parent is MemberDeclarationSyntax declarationParent)
167166
{
168167
return declarationParent;
169168
}

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1500CodeFixProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen
5757

5858
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, cancellationToken);
5959
var braceToken = syntaxRoot.FindToken(diagnostic.Location.SourceSpan.Start);
60-
var tokenReplacements = GenerateBraceFixes(document, settings.Indentation, ImmutableArray.Create(braceToken));
60+
var tokenReplacements = GenerateBraceFixes(settings.Indentation, ImmutableArray.Create(braceToken));
6161

6262
var newSyntaxRoot = syntaxRoot.ReplaceTokens(tokenReplacements.Keys, (originalToken, rewrittenToken) => tokenReplacements[originalToken]);
6363
return document.WithSyntaxRoot(newSyntaxRoot);
6464
}
6565

66-
private static Dictionary<SyntaxToken, SyntaxToken> GenerateBraceFixes(Document document, IndentationSettings indentationSettings, ImmutableArray<SyntaxToken> braceTokens)
66+
private static Dictionary<SyntaxToken, SyntaxToken> GenerateBraceFixes(IndentationSettings indentationSettings, ImmutableArray<SyntaxToken> braceTokens)
6767
{
6868
var tokenReplacements = new Dictionary<SyntaxToken, SyntaxToken>();
6969

@@ -284,7 +284,7 @@ protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fi
284284

285285
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, fixAllContext.CancellationToken);
286286

287-
var tokenReplacements = GenerateBraceFixes(document, settings.Indentation, tokens);
287+
var tokenReplacements = GenerateBraceFixes(settings.Indentation, tokens);
288288

289289
return syntaxRoot.ReplaceTokens(tokenReplacements.Keys, (originalToken, rewrittenToken) => tokenReplacements[originalToken]);
290290
}

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1502CodeFixProvider.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ private SyntaxNode RegisterLocalFunctionStatementCodeFix(SyntaxNode syntaxRoot,
117117
return this.ReformatElement(syntaxRoot, node, node.Body.OpenBraceToken, node.Body.CloseBraceToken, indentationSettings);
118118
}
119119

120-
private SyntaxNode RegisterEnumDeclarationCodeFix(SyntaxNode syntaxRoot, EnumDeclarationSyntax node, IndentationSettings indentationSettings)
121-
{
122-
return this.ReformatElement(syntaxRoot, node, node.OpenBraceToken, node.CloseBraceToken, indentationSettings);
123-
}
124-
125120
private SyntaxNode RegisterNamespaceDeclarationCodeFix(SyntaxNode syntaxRoot, NamespaceDeclarationSyntax node, IndentationSettings indentationSettings)
126121
{
127122
return this.ReformatElement(syntaxRoot, node, node.OpenBraceToken, node.CloseBraceToken, indentationSettings);

0 commit comments

Comments
 (0)