diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/FileHeaderCodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/FileHeaderCodeFixProvider.cs index 0b0386faf..532e9c42b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/FileHeaderCodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/FileHeaderCodeFixProvider.cs @@ -316,7 +316,7 @@ private static SyntaxNode ReplaceHeader(Document document, SyntaxNode root, Styl // Does the copyright element have leading whitespace? If so remove it. if ((copyrightTriviaIndex.Value > 0) && trivia[copyrightTriviaIndex.Value - 1].IsKind(SyntaxKind.WhitespaceTrivia)) { - copyrightTriviaIndex = copyrightTriviaIndex - 1; + copyrightTriviaIndex--; trivia = trivia.RemoveAt(copyrightTriviaIndex.Value); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/InheritdocCodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/InheritdocCodeFixProvider.cs index f5dd35aea..cfd2e0d29 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/InheritdocCodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/InheritdocCodeFixProvider.cs @@ -90,36 +90,36 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) context.RegisterCodeFix( CodeAction.Create( DocumentationResources.InheritdocCodeFix, - cancellationToken => GetTransformedDocumentAsync(context.Document, diagnostic, root, identifierToken, cancellationToken), + cancellationToken => GetTransformedDocumentAsync(context.Document, root, identifierToken, cancellationToken), nameof(InheritdocCodeFixProvider)), diagnostic); } } - private static async Task GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, SyntaxNode root, SyntaxToken identifierToken, CancellationToken cancellationToken) + private static async Task GetTransformedDocumentAsync(Document document, SyntaxNode root, SyntaxToken identifierToken, CancellationToken cancellationToken) { SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); switch (identifierToken.Parent.Kind()) { case SyntaxKind.PropertyDeclaration: case SyntaxKind.EventDeclaration: - return GetTransformedDocumentForBasePropertyDeclaration(document, diagnostic, root, semanticModel, (BasePropertyDeclarationSyntax)identifierToken.Parent, cancellationToken); + return GetTransformedDocumentForBasePropertyDeclaration(document, root, semanticModel, (BasePropertyDeclarationSyntax)identifierToken.Parent, cancellationToken); case SyntaxKind.MethodDeclaration: - return GetTransformedDocumentForMethodDeclaration(document, diagnostic, root, semanticModel, (MethodDeclarationSyntax)identifierToken.Parent, cancellationToken); + return GetTransformedDocumentForMethodDeclaration(document, root, semanticModel, (MethodDeclarationSyntax)identifierToken.Parent, cancellationToken); case SyntaxKind.VariableDeclarator: - return GetTransformedDocumentForEventFieldDeclaration(document, diagnostic, root, semanticModel, (EventFieldDeclarationSyntax)identifierToken.Parent.Parent.Parent, cancellationToken); + return GetTransformedDocumentForEventFieldDeclaration(document, root, semanticModel, (EventFieldDeclarationSyntax)identifierToken.Parent.Parent.Parent, cancellationToken); case SyntaxKind.IndexerDeclaration: - return GetTransformedDocumentForIndexerDeclaration(document, diagnostic, root, semanticModel, (IndexerDeclarationSyntax)identifierToken.Parent, cancellationToken); + return GetTransformedDocumentForIndexerDeclaration(document, root, semanticModel, (IndexerDeclarationSyntax)identifierToken.Parent, cancellationToken); default: return document; } } - private static Document GetTransformedDocumentForBasePropertyDeclaration(Document document, Diagnostic diagnostic, SyntaxNode root, SemanticModel semanticModel, BasePropertyDeclarationSyntax basePropertyDeclaration, CancellationToken cancellationToken) + private static Document GetTransformedDocumentForBasePropertyDeclaration(Document document, SyntaxNode root, SemanticModel semanticModel, BasePropertyDeclarationSyntax basePropertyDeclaration, CancellationToken cancellationToken) { if (basePropertyDeclaration.ExplicitInterfaceSpecifier == null && !basePropertyDeclaration.Modifiers.Any(SyntaxKind.OverrideKeyword)) { @@ -130,10 +130,10 @@ private static Document GetTransformedDocumentForBasePropertyDeclaration(Documen } } - return InsertInheritdocComment(document, diagnostic, root, basePropertyDeclaration, cancellationToken); + return InsertInheritdocComment(document, root, basePropertyDeclaration, cancellationToken); } - private static Document GetTransformedDocumentForMethodDeclaration(Document document, Diagnostic diagnostic, SyntaxNode root, SemanticModel semanticModel, MethodDeclarationSyntax methodDeclaration, CancellationToken cancellationToken) + private static Document GetTransformedDocumentForMethodDeclaration(Document document, SyntaxNode root, SemanticModel semanticModel, MethodDeclarationSyntax methodDeclaration, CancellationToken cancellationToken) { if (methodDeclaration.ExplicitInterfaceSpecifier == null && !methodDeclaration.Modifiers.Any(SyntaxKind.OverrideKeyword)) { @@ -144,10 +144,10 @@ private static Document GetTransformedDocumentForMethodDeclaration(Document docu } } - return InsertInheritdocComment(document, diagnostic, root, methodDeclaration, cancellationToken); + return InsertInheritdocComment(document, root, methodDeclaration, cancellationToken); } - private static Document GetTransformedDocumentForEventFieldDeclaration(Document document, Diagnostic diagnostic, SyntaxNode root, SemanticModel semanticModel, EventFieldDeclarationSyntax eventFieldDeclaration, CancellationToken cancellationToken) + private static Document GetTransformedDocumentForEventFieldDeclaration(Document document, SyntaxNode root, SemanticModel semanticModel, EventFieldDeclarationSyntax eventFieldDeclaration, CancellationToken cancellationToken) { if (!eventFieldDeclaration.Modifiers.Any(SyntaxKind.OverrideKeyword)) { @@ -164,10 +164,10 @@ private static Document GetTransformedDocumentForEventFieldDeclaration(Document } } - return InsertInheritdocComment(document, diagnostic, root, eventFieldDeclaration, cancellationToken); + return InsertInheritdocComment(document, root, eventFieldDeclaration, cancellationToken); } - private static Document GetTransformedDocumentForIndexerDeclaration(Document document, Diagnostic diagnostic, SyntaxNode root, SemanticModel semanticModel, IndexerDeclarationSyntax indexerDeclaration, CancellationToken cancellationToken) + private static Document GetTransformedDocumentForIndexerDeclaration(Document document, SyntaxNode root, SemanticModel semanticModel, IndexerDeclarationSyntax indexerDeclaration, CancellationToken cancellationToken) { if (indexerDeclaration.ExplicitInterfaceSpecifier == null && !indexerDeclaration.Modifiers.Any(SyntaxKind.OverrideKeyword)) { @@ -178,11 +178,14 @@ private static Document GetTransformedDocumentForIndexerDeclaration(Document doc } } - return InsertInheritdocComment(document, diagnostic, root, indexerDeclaration, cancellationToken); + return InsertInheritdocComment(document, root, indexerDeclaration, cancellationToken); } - private static Document InsertInheritdocComment(Document document, Diagnostic diagnostic, SyntaxNode root, SyntaxNode syntaxNode, CancellationToken cancellationToken) + private static Document InsertInheritdocComment(Document document, SyntaxNode root, SyntaxNode syntaxNode, CancellationToken cancellationToken) { + // Currently unused + _ = cancellationToken; + SyntaxTriviaList leadingTrivia = syntaxNode.GetLeadingTrivia(); int insertionIndex = leadingTrivia.Count; while (insertionIndex > 0 && !leadingTrivia[insertionIndex - 1].HasBuiltinEndLine()) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1600CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1600CodeFixProvider.cs index 04ec8da93..a1c00a461 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1600CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1600CodeFixProvider.cs @@ -59,7 +59,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) context.RegisterCodeFix( CodeAction.Create( DocumentationResources.ConstructorDocumentationCodeFix, - cancellationToken => GetConstructorOrDestructorDocumentationTransformedDocumentAsync(context.Document, diagnostic, root, (BaseMethodDeclarationSyntax)identifierToken.Parent, cancellationToken), + cancellationToken => GetConstructorOrDestructorDocumentationTransformedDocumentAsync(context.Document, root, (BaseMethodDeclarationSyntax)identifierToken.Parent, cancellationToken), nameof(SA1600CodeFixProvider)), diagnostic); break; @@ -72,7 +72,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) context.RegisterCodeFix( CodeAction.Create( DocumentationResources.MethodDocumentationCodeFix, - cancellationToken => GetMethodDocumentationTransformedDocumentAsync(context.Document, diagnostic, root, semanticModel, (MethodDeclarationSyntax)identifierToken.Parent, cancellationToken), + cancellationToken => GetMethodDocumentationTransformedDocumentAsync(context.Document, root, semanticModel, (MethodDeclarationSyntax)identifierToken.Parent, cancellationToken), nameof(SA1600CodeFixProvider)), diagnostic); } @@ -98,7 +98,7 @@ private static bool IsCoveredByInheritDoc(SemanticModel semanticModel, MethodDec return (declaredSymbol != null) && NamedTypeHelpers.IsImplementingAnInterfaceMember(declaredSymbol); } - private static Task GetConstructorOrDestructorDocumentationTransformedDocumentAsync(Document document, Diagnostic diagnostic, SyntaxNode root, BaseMethodDeclarationSyntax declaration, CancellationToken cancellationToken) + private static Task GetConstructorOrDestructorDocumentationTransformedDocumentAsync(Document document, SyntaxNode root, BaseMethodDeclarationSyntax declaration, CancellationToken cancellationToken) { SyntaxTriviaList leadingTrivia = declaration.GetLeadingTrivia(); int insertionIndex = GetInsertionIndex(ref leadingTrivia); @@ -136,7 +136,7 @@ private static Task GetConstructorOrDestructorDocumentationTransformed return Task.FromResult(document.WithSyntaxRoot(root.ReplaceNode(declaration, newElement))); } - private static Task GetMethodDocumentationTransformedDocumentAsync(Document document, Diagnostic diagnostic, SyntaxNode root, SemanticModel semanticModel, MethodDeclarationSyntax methodDeclaration, CancellationToken cancellationToken) + private static Task GetMethodDocumentationTransformedDocumentAsync(Document document, SyntaxNode root, SemanticModel semanticModel, MethodDeclarationSyntax methodDeclaration, CancellationToken cancellationToken) { SyntaxTriviaList leadingTrivia = methodDeclaration.GetLeadingTrivia(); int insertionIndex = GetInsertionIndex(ref leadingTrivia); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1609SA1610CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1609SA1610CodeFixProvider.cs index 3a8c9e861..644287bd9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1609SA1610CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1609SA1610CodeFixProvider.cs @@ -174,7 +174,7 @@ private bool TryRemoveSummaryPrefix(ref SyntaxList summaryContent } // Find the token containing the prefix, such as "Gets or sets " - SyntaxToken prefixToken = default(SyntaxToken); + SyntaxToken prefixToken = default; foreach (SyntaxToken textToken in firstText.TextTokens) { if (textToken.IsMissing) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1626CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1626CodeFixProvider.cs index 4c6c54893..89fa89f7b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1626CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1626CodeFixProvider.cs @@ -53,7 +53,6 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) private static async Task GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) { - var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); TextChange textChange = new TextChange(new TextSpan(diagnostic.Location.SourceSpan.Start, 1), string.Empty); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1642SA1643CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1642SA1643CodeFixProvider.cs index 2dee644d6..69b5877d4 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1642SA1643CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1642SA1643CodeFixProvider.cs @@ -147,7 +147,7 @@ private static Task GetTransformedDocumentAsync(Document document, Syn string trailingString = string.Empty; - var newContent = RemoveMalformattedStandardText(node.Content, typeDeclaration.Identifier, standardText[0], standardText[1], ref trailingString); + var newContent = RemoveMalformattedStandardText(node.Content, standardText[0], standardText[1], ref trailingString); if (newContent.Count == 1 && newContent[0] is XmlTextSyntax xmlText) { @@ -174,8 +174,6 @@ private static Task GetTransformedDocumentAsync(Document document, Syn private static Task GetTransformedDocumentAsync(Document document, SyntaxNode root, XmlEmptyElementSyntax node) { var typeDeclaration = node.FirstAncestorOrSelf(); - var declarationSyntax = node.FirstAncestorOrSelf(); - bool isStruct = typeDeclaration.IsKind(SyntaxKind.StructDeclaration); TypeParameterListSyntax typeParameterList; if (typeDeclaration is ClassDeclarationSyntax classDeclaration) @@ -194,7 +192,7 @@ private static Task GetTransformedDocumentAsync(Document document, Syn return Task.FromResult(newDocument); } - private static SyntaxList RemoveMalformattedStandardText(SyntaxList content, SyntaxToken identifier, string preText, string postText, ref string trailingString) + private static SyntaxList RemoveMalformattedStandardText(SyntaxList content, string preText, string postText, ref string trailingString) { var regex = new Regex(@"^\s*" + Regex.Escape(preText) + "[^ ]+" + Regex.Escape(postText)); var item = content.OfType().FirstOrDefault(); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/FormattingHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/FormattingHelper.cs index a951c085a..e6bacdff4 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/FormattingHelper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/FormattingHelper.cs @@ -92,7 +92,7 @@ public static SyntaxTrivia WithoutFormatting(this SyntaxTrivia trivia) } } - return WithoutFormattingImpl(trivia); + return WithoutFormattingImpl(result); } /// diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/RenameHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/RenameHelper.cs index f5cc9adc0..08e8cce87 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/RenameHelper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/RenameHelper.cs @@ -162,8 +162,7 @@ public static SyntaxNode GetParentDeclaration(SyntaxToken token) return parent; default: - var declarationParent = parent as MemberDeclarationSyntax; - if (declarationParent != null) + if (parent is MemberDeclarationSyntax declarationParent) { return declarationParent; } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1500CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1500CodeFixProvider.cs index 09bbb207e..52fd0b3fe 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1500CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1500CodeFixProvider.cs @@ -57,13 +57,13 @@ private static async Task GetTransformedDocumentAsync(Document documen var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, cancellationToken); var braceToken = syntaxRoot.FindToken(diagnostic.Location.SourceSpan.Start); - var tokenReplacements = GenerateBraceFixes(document, settings.Indentation, ImmutableArray.Create(braceToken)); + var tokenReplacements = GenerateBraceFixes(settings.Indentation, ImmutableArray.Create(braceToken)); var newSyntaxRoot = syntaxRoot.ReplaceTokens(tokenReplacements.Keys, (originalToken, rewrittenToken) => tokenReplacements[originalToken]); return document.WithSyntaxRoot(newSyntaxRoot); } - private static Dictionary GenerateBraceFixes(Document document, IndentationSettings indentationSettings, ImmutableArray braceTokens) + private static Dictionary GenerateBraceFixes(IndentationSettings indentationSettings, ImmutableArray braceTokens) { var tokenReplacements = new Dictionary(); @@ -284,7 +284,7 @@ protected override async Task FixAllInDocumentAsync(FixAllContext fi var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, fixAllContext.CancellationToken); - var tokenReplacements = GenerateBraceFixes(document, settings.Indentation, tokens); + var tokenReplacements = GenerateBraceFixes(settings.Indentation, tokens); return syntaxRoot.ReplaceTokens(tokenReplacements.Keys, (originalToken, rewrittenToken) => tokenReplacements[originalToken]); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1502CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1502CodeFixProvider.cs index feaaace70..c0b6a201b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1502CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1502CodeFixProvider.cs @@ -117,11 +117,6 @@ private SyntaxNode RegisterLocalFunctionStatementCodeFix(SyntaxNode syntaxRoot, return this.ReformatElement(syntaxRoot, node, node.Body.OpenBraceToken, node.Body.CloseBraceToken, indentationSettings); } - private SyntaxNode RegisterEnumDeclarationCodeFix(SyntaxNode syntaxRoot, EnumDeclarationSyntax node, IndentationSettings indentationSettings) - { - return this.ReformatElement(syntaxRoot, node, node.OpenBraceToken, node.CloseBraceToken, indentationSettings); - } - private SyntaxNode RegisterNamespaceDeclarationCodeFix(SyntaxNode syntaxRoot, NamespaceDeclarationSyntax node, IndentationSettings indentationSettings) { return this.ReformatElement(syntaxRoot, node, node.OpenBraceToken, node.CloseBraceToken, indentationSettings); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1503CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1503CodeFixProvider.cs index b6b8878aa..9f0051f9c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1503CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1503CodeFixProvider.cs @@ -64,6 +64,9 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) private static Task GetTransformedDocumentAsync(Document document, SyntaxNode root, StatementSyntax node, CancellationToken cancellationToken) { + // Currently unused + _ = cancellationToken; + var newSyntaxRoot = root.ReplaceNode(node, SyntaxFactory.Block(node)); return Task.FromResult(document.WithSyntaxRoot(newSyntaxRoot)); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1516CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1516CodeFixProvider.cs index 98082f3dc..b83b5b579 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1516CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1516CodeFixProvider.cs @@ -78,6 +78,9 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) private static Task GetTransformedDocumentAsync(Document document, SyntaxNode syntaxRoot, Diagnostic diagnostic, bool insertBlankLine, CancellationToken cancellationToken) { + // Currently unused + _ = cancellationToken; + var node = syntaxRoot.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true); node = GetRelevantNode(node); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1407SA1408FixAllProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1407SA1408FixAllProvider.cs index 816d1923b..377c1930c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1407SA1408FixAllProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1407SA1408FixAllProvider.cs @@ -37,14 +37,14 @@ protected override async Task FixAllInDocumentAsync(FixAllContext fi nodes.Add(node); } - return root.ReplaceNodes(nodes, (originalNode, rewrittenNode) => AddParentheses(originalNode, rewrittenNode)); + return root.ReplaceNodes(nodes, (originalNode, rewrittenNode) => AddParentheses(rewrittenNode)); } - private static SyntaxNode AddParentheses(SyntaxNode originalNode, SyntaxNode rewrittenNode) + private static SyntaxNode AddParentheses(SyntaxNode node) { - if (!(rewrittenNode is BinaryExpressionSyntax syntax)) + if (!(node is BinaryExpressionSyntax syntax)) { - return rewrittenNode; + return node; } BinaryExpressionSyntax trimmedSyntax = syntax.WithoutTrivia(); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/NamingRules/RenameToUpperCaseCodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/NamingRules/RenameToUpperCaseCodeFixProvider.cs index 64da69570..727f8fd9f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/NamingRules/RenameToUpperCaseCodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/NamingRules/RenameToUpperCaseCodeFixProvider.cs @@ -63,7 +63,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) if (memberSyntax is NamespaceDeclarationSyntax) { // namespaces are not symbols. So we are just renaming the namespace - Func> renameNamespace = cancellationToken => + Task RenameNamespace(CancellationToken cancellationToken) { IdentifierNameSyntax identifierSyntax = (IdentifierNameSyntax)token.Parent; @@ -71,12 +71,12 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) var newRoot = root.ReplaceNode(identifierSyntax, newIdentifierSyntax); return Task.FromResult(context.Document.WithSyntaxRoot(newRoot)); - }; + } context.RegisterCodeFix( CodeAction.Create( string.Format(NamingResources.RenameToCodeFix, newName), - renameNamespace, + (Func>)RenameNamespace, nameof(RenameToUpperCaseCodeFixProvider) + "_" + diagnostic.Id), diagnostic); } @@ -96,7 +96,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) && !await RenameHelper.IsValidNewMemberNameAsync(semanticModel, declaredSymbol, newName, context.CancellationToken).ConfigureAwait(false)) { usedSuffix = true; - newName = newName + Suffix; + newName += Suffix; } int index = 0; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/ElementOrderCodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/ElementOrderCodeFixProvider.cs index f1285613b..3ecfad2c5 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/ElementOrderCodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/ElementOrderCodeFixProvider.cs @@ -113,7 +113,7 @@ private static SyntaxNode HandleNamespaceDeclaration(MemberOrderHelper memberOrd private static SyntaxNode OrderMember(MemberOrderHelper memberOrder, SyntaxList members, ImmutableArray elementOrder, SyntaxNode syntaxRoot, IndentationSettings indentationSettings) { var memberIndex = members.IndexOf(memberOrder.Member); - MemberOrderHelper target = default(MemberOrderHelper); + MemberOrderHelper target = default; for (var i = memberIndex - 1; i >= 0; --i) { diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.SourceMap.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.SourceMap.cs index 3acb210e0..24c515f46 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.SourceMap.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.SourceMap.cs @@ -146,7 +146,7 @@ private static void BuildDirectiveTriviaMaps(CompilationUnitSyntax compilationUn switch (directiveTrivia.Kind()) { case SyntaxKind.IfDirectiveTrivia: - AddNewDirectiveTriviaSpan(conditionalBuilder, conditionalStack, directiveTrivia); + AddNewDirectiveTriviaSpan(conditionalStack, directiveTrivia); break; case SyntaxKind.ElifDirectiveTrivia: @@ -154,19 +154,19 @@ private static void BuildDirectiveTriviaMaps(CompilationUnitSyntax compilationUn var previousSpan = conditionalStack.Pop(); previousSpan.SetEnd(directiveTrivia.FullSpan.Start); - AddNewDirectiveTriviaSpan(conditionalBuilder, conditionalStack, directiveTrivia); + AddNewDirectiveTriviaSpan(conditionalStack, directiveTrivia); break; case SyntaxKind.EndIfDirectiveTrivia: - CloseDirectiveTriviaSpan(conditionalBuilder, conditionalStack, directiveTrivia); + CloseDirectiveTriviaSpan(conditionalStack, directiveTrivia); break; case SyntaxKind.RegionDirectiveTrivia: - AddNewDirectiveTriviaSpan(regionBuilder, regionStack, directiveTrivia); + AddNewDirectiveTriviaSpan(regionStack, directiveTrivia); break; case SyntaxKind.EndRegionDirectiveTrivia: - CloseDirectiveTriviaSpan(regionBuilder, regionStack, directiveTrivia); + CloseDirectiveTriviaSpan(regionStack, directiveTrivia); break; case SyntaxKind.PragmaWarningDirectiveTrivia: @@ -192,14 +192,14 @@ private static TreeTextSpan.Builder SetupBuilder(CompilationUnitSyntax compilati return rootBuilder; } - private static void AddNewDirectiveTriviaSpan(TreeTextSpan.Builder spanBuilder, Stack spanStack, DirectiveTriviaSyntax directiveTrivia) + private static void AddNewDirectiveTriviaSpan(Stack spanStack, DirectiveTriviaSyntax directiveTrivia) { var parent = spanStack.Peek(); var newDirectiveSpan = parent.AddChild(directiveTrivia.FullSpan.Start); spanStack.Push(newDirectiveSpan); } - private static void CloseDirectiveTriviaSpan(TreeTextSpan.Builder spanBuilder, Stack spanStack, DirectiveTriviaSyntax directiveTrivia) + private static void CloseDirectiveTriviaSpan(Stack spanStack, DirectiveTriviaSyntax directiveTrivia) { var previousSpan = spanStack.Pop(); previousSpan.SetEnd(directiveTrivia.FullSpan.End); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.TreeTextSpan.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.TreeTextSpan.cs index 37c5634dc..566cd0d1f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.TreeTextSpan.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.TreeTextSpan.cs @@ -158,7 +158,7 @@ internal TreeTextSpan GetContainingSpan(TextSpan textSpan) internal class Builder { private readonly List children = new List(); - private int start; + private readonly int start; private int end = int.MaxValue; /// diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.cs index b0e20c5d0..ef1acbef8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.cs @@ -480,7 +480,7 @@ public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia) { if (this.fileHeader.Contains(trivia)) { - return default(SyntaxTrivia); + return default; } return base.VisitTrivia(trivia); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/IndentationCodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/IndentationCodeFixProvider.cs index 04c28e100..24a331e46 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/IndentationCodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/IndentationCodeFixProvider.cs @@ -61,14 +61,14 @@ private static bool TryGetTextChange(Diagnostic diagnostic, SyntaxNode syntaxRoo string replacement; if (!diagnostic.Properties.TryGetValue(SA1137ElementsShouldHaveTheSameIndentation.ExpectedIndentationKey, out replacement)) { - textChange = default(TextChange); + textChange = default; return false; } var trivia = syntaxRoot.FindTrivia(diagnostic.Location.SourceSpan.Start); TextSpan originalSpan; - if (trivia == default(SyntaxTrivia)) + if (trivia == default) { // The warning was reported on a token because the line is not indented originalSpan = new TextSpan(diagnostic.Location.SourceSpan.Start, 0); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1120CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1120CodeFixProvider.cs index 05c2d0c52..6dd5499ed 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1120CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1120CodeFixProvider.cs @@ -80,7 +80,7 @@ private static async Task GetTransformedDocumentAsync(Document documen } // Replace all roots with an empty node - var newRoot = root.ReplaceTrivia(triviaToRemove, (original, rewritten) => default(SyntaxTrivia)); + var newRoot = root.ReplaceTrivia(triviaToRemove, (original, rewritten) => default); Document updatedDocument = document.WithSyntaxRoot(newRoot); return updatedDocument; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1129CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1129CodeFixProvider.cs index c93affbe8..5c8353ea8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1129CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1129CodeFixProvider.cs @@ -65,8 +65,7 @@ private static SyntaxNode GetReplacementNode(SyntaxNode node, SemanticModel sema var symbolInfo = semanticModel.GetSymbolInfo(newExpression.Type, cancellationToken); var namedTypeSymbol = symbolInfo.Symbol as INamedTypeSymbol; - SyntaxNode replacement = null; - string memberName = null; + SyntaxNode replacement; if (IsType(namedTypeSymbol)) { @@ -79,7 +78,7 @@ private static SyntaxNode GetReplacementNode(SyntaxNode node, SemanticModel sema replacement = ConstructMemberAccessSyntax(newExpression.Type, nameof(CancellationToken.None)); } } - else if (IsEnumWithDefaultMember(namedTypeSymbol, out memberName)) + else if (IsEnumWithDefaultMember(namedTypeSymbol, out string memberName)) { replacement = ConstructMemberAccessSyntax(newExpression.Type, memberName); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1130CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1130CodeFixProvider.cs index 60b6ed3b2..fe74e382a 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1130CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1130CodeFixProvider.cs @@ -76,7 +76,7 @@ private static SyntaxNode ReplaceWithLambda(SemanticModel semanticModel, Anonymo if (parameterList == null) { - ImmutableArray argumentList = default(ImmutableArray); + ImmutableArray argumentList = default; switch (anonymousMethod.Parent.Kind()) { @@ -209,8 +209,7 @@ private static ImmutableArray GetEqualsArgumentList(SemanticModel semant private static ImmutableArray GetMemberReturnTypeArgumentList(SemanticModel semanticModel, AnonymousMethodExpressionSyntax anonymousMethod) { var enclosingSymbol = semanticModel.GetEnclosingSymbol(anonymousMethod.Parent.SpanStart); - var returnType = ((IMethodSymbol)enclosingSymbol).ReturnType as INamedTypeSymbol; - return (returnType == null) ? ImmutableArray.Empty : returnType.DelegateInvokeMethod.Parameters.Select(ps => ps.Name).ToImmutableArray(); + return !(((IMethodSymbol)enclosingSymbol).ReturnType is INamedTypeSymbol returnType) ? ImmutableArray.Empty : returnType.DelegateInvokeMethod.Parameters.Select(ps => ps.Name).ToImmutableArray(); } private static List GenerateUniqueParameterNames(SemanticModel semanticModel, AnonymousMethodExpressionSyntax anonymousMethod, ImmutableArray argumentNames) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Settings/SettingsFileCodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Settings/SettingsFileCodeFixProvider.cs index 5225e02c3..fb917066c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Settings/SettingsFileCodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Settings/SettingsFileCodeFixProvider.cs @@ -79,7 +79,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) context.RegisterCodeFix( CodeAction.Create( SettingsResources.SettingsFileCodeFix, - cancellationToken => GetTransformedSolutionAsync(context.Document, diagnostic, cancellationToken), + cancellationToken => GetTransformedSolutionAsync(context.Document, cancellationToken), nameof(SettingsFileCodeFixProvider)), diagnostic); } @@ -94,8 +94,11 @@ public override FixAllProvider GetFixAllProvider() return null; } - private static Task GetTransformedSolutionAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) + private static Task GetTransformedSolutionAsync(Document document, CancellationToken cancellationToken) { + // Currently unused + _ = cancellationToken; + var project = document.Project; var solution = project.Solution; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/SpacingRules/SA1004CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/SpacingRules/SA1004CodeFixProvider.cs index 216c93f65..15fd44f2b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/SpacingRules/SA1004CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/SpacingRules/SA1004CodeFixProvider.cs @@ -55,10 +55,10 @@ private static async Task GetTransformedDocumentAsync(Document documen { var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); - return document.WithText(text.WithChanges(GetTextChange(root, text, diagnostic))); + return document.WithText(text.WithChanges(GetTextChange(root, diagnostic))); } - private static TextChange GetTextChange(SyntaxNode root, SourceText sourceText, Diagnostic diagnostic) + private static TextChange GetTextChange(SyntaxNode root, Diagnostic diagnostic) { var token = root.FindToken(diagnostic.Location.SourceSpan.Start, findInsideTrivia: true); switch (token.Kind()) @@ -93,7 +93,7 @@ protected override async Task FixAllInDocumentAsync(FixAllContext fi List changes = new List(); foreach (var diagnostic in diagnostics) { - changes.Add(GetTextChange(root, text, diagnostic)); + changes.Add(GetTextChange(root, diagnostic)); } changes.Sort((left, right) => left.Span.Start.CompareTo(right.Span.Start)); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/SpacingRules/SA1027CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/SpacingRules/SA1027CodeFixProvider.cs index 4429ddf55..0f18caba8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/SpacingRules/SA1027CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/SpacingRules/SA1027CodeFixProvider.cs @@ -86,7 +86,7 @@ private static TextChange FixDiagnostic(IndentationSettings indentationSettings, { if (useTabs) { - replacement.Length = replacement.Length - spaceCount; + replacement.Length -= spaceCount; replacement.Append('\t'); spaceCount = 0; } @@ -113,7 +113,7 @@ private static TextChange FixDiagnostic(IndentationSettings indentationSettings, if (offsetWithinTabColumn == 0) { // We reached a tab stop. - replacement.Length = replacement.Length - spaceCount; + replacement.Length -= spaceCount; replacement.Append('\t'); spaceCount = 0; } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Status.Generator/SolutionReader.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Status.Generator/SolutionReader.cs index 317ae789e..222b1be76 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Status.Generator/SolutionReader.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Status.Generator/SolutionReader.cs @@ -24,7 +24,7 @@ namespace StyleCop.Analyzers.Status.Generator /// public class SolutionReader { - private static Regex diagnosticPathRegex = new Regex(@"(?[A-Za-z]+)Rules\\(?[A-Za-z0-9]+)\.cs$"); + private static readonly Regex DiagnosticPathRegex = new Regex(@"(?[A-Za-z]+)Rules\\(?[A-Za-z0-9]+)\.cs$"); private INamedTypeSymbol diagnosticAnalyzerTypeSymbol; private INamedTypeSymbol noCodeFixAttributeTypeSymbol; @@ -93,7 +93,7 @@ public async Task> GetDiagnosticsAsync() foreach (var syntaxTree in syntaxTrees) { - var match = diagnosticPathRegex.Match(syntaxTree.FilePath); + var match = DiagnosticPathRegex.Match(syntaxTree.FilePath); if (!match.Success) { continue; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/NoXmlFileHeaderUnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/NoXmlFileHeaderUnitTests.cs index 6af113058..3b5ea7ab4 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/NoXmlFileHeaderUnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/NoXmlFileHeaderUnitTests.cs @@ -392,9 +392,6 @@ namespace Bar await VerifyCSharpFixAsync(testCode, TestSettingsWithEmptyLines, new[] { expected }, fixedCode, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpFixAsync(source, TestSettings, new[] { expected }, fixedSource: null, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) => VerifyCSharpFixAsync(source, TestSettings, expected, fixedSource: null, cancellationToken); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1609UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1609UnitTests.cs index 1bd51200f..dd88ed39f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1609UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1609UnitTests.cs @@ -369,9 +369,6 @@ private int Property await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpFixAsync(source, new[] { expected }, fixedSource: null, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) => VerifyCSharpFixAsync(source, expected, fixedSource: null, cancellationToken); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1610UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1610UnitTests.cs index 50d627375..cd8e76b6f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1610UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1610UnitTests.cs @@ -362,9 +362,6 @@ public int Property await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpFixAsync(source, new[] { expected }, fixedSource: null, offerEmptyFixer: false, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) => VerifyCSharpFixAsync(source, expected, fixedSource: null, offerEmptyFixer: false, cancellationToken); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1611UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1611UnitTests.cs index 4055462b7..a3dc8406e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1611UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1611UnitTests.cs @@ -334,9 +334,6 @@ public void TestMethod(string param1, string param2, string param3) await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpDiagnosticAsync(source, new[] { expected }, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { string contentWithoutElementDocumentation = @" diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1613UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1613UnitTests.cs index d58a729fe..160df8993 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1613UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1613UnitTests.cs @@ -218,9 +218,6 @@ public class ClassName await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpDiagnosticAsync(source, new[] { expected }, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { string contentWithoutParamDocumentation = @" diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1614UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1614UnitTests.cs index cb40c5d2c..19760f688 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1614UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1614UnitTests.cs @@ -229,9 +229,6 @@ public class ClassName await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpDiagnosticAsync(source, new[] { expected }, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { string contentWithoutDocumentation = @" diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1616UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1616UnitTests.cs index 2ec016c2f..556d0eb4f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1616UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1616UnitTests.cs @@ -531,9 +531,6 @@ public class ClassName await VerifyCSharpFixAsync(testCode, expected, testCode, offerEmptyFixer: true, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpFixAsync(source, new[] { expected }, fixedSource: null, offerEmptyFixer: false, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) => VerifyCSharpFixAsync(source, expected, fixedSource: null, offerEmptyFixer: false, cancellationToken); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1617UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1617UnitTests.cs index 1f0e9df50..d9b842629 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1617UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1617UnitTests.cs @@ -316,9 +316,6 @@ public void Method() { } await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpFixAsync(source, new[] { expected }, fixedSource: null, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) => VerifyCSharpFixAsync(source, expected, fixedSource: null, cancellationToken); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1621UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1621UnitTests.cs index 97c62de65..649a15f23 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1621UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1621UnitTests.cs @@ -332,9 +332,6 @@ public class TestClass await VerifyCSharpDiagnosticAsync(testCode.Replace("##", p), expected, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpDiagnosticAsync(source, new[] { expected }, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { var test = CreateTest(expected); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1622UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1622UnitTests.cs index be90b7bae..8991d2295 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1622UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1622UnitTests.cs @@ -306,9 +306,6 @@ public class TestClass await VerifyCSharpDiagnosticAsync(testCode.Replace("##", memberText), expected, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpDiagnosticAsync(source, new[] { expected }, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { var test = CreateTest(expected); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1626UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1626UnitTests.cs index 72fad4023..1d62e482f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1626UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1626UnitTests.cs @@ -15,8 +15,6 @@ namespace StyleCop.Analyzers.Test.DocumentationRules public class SA1626UnitTests { - private const string DiagnosticId = SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes.DiagnosticId; - [Fact] public async Task TestClassWithXmlCommentAsync() { diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs index 01e5d64e2..c94a682a9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs @@ -849,9 +849,6 @@ public interface ITest await VerifyCSharpDiagnosticAsync(testCode, testSettings, expectedResult, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpDiagnosticAsync(source, testSettings: null, new[] { expected }, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) => VerifyCSharpDiagnosticAsync(source, testSettings: null, expected, cancellationToken); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs index 27cf86735..c17a938bc 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs @@ -1202,9 +1202,6 @@ private static async Task TestConstructorSimpleDocumentationWrongTypeNameAsync(s await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpDiagnosticAsync(source, testSettings: null, new[] { expected }, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) => VerifyCSharpDiagnosticAsync(source, testSettings: null, expected, cancellationToken); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1651UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1651UnitTests.cs index 76b2080d0..35b523863 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1651UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1651UnitTests.cs @@ -247,9 +247,6 @@ public class TestClass await VerifyCSharpFixAsync(testCode, expected, testCode, CancellationToken.None).ConfigureAwait(false); } - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) - => VerifyCSharpDiagnosticAsync(source, new[] { expected }, cancellationToken); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { var test = CreateTest(expected); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/IndentationHelperTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/IndentationHelperTests.cs index e95e1ceaa..f4e45572b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/IndentationHelperTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/IndentationHelperTests.cs @@ -179,7 +179,7 @@ private static Document CreateTestDocument(string source, int indentationSize = }} }} "; - var settingsDocumentId = DocumentId.CreateNewId(projectId); + solution = solution.AddAdditionalDocument(documentId, SettingsHelper.SettingsFileName, settings); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/ObjectPools/ObjectPoolTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/ObjectPools/ObjectPoolTests.cs index 23b5f6fc5..3aaf4ac40 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/ObjectPools/ObjectPoolTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/ObjectPools/ObjectPoolTests.cs @@ -13,16 +13,16 @@ public class ObjectPoolTests [Fact] public void TestDefaultConstructor() { - Func factory = () => new object(); - var pool = new ObjectPool(factory); + object Factory() => new object(); + var pool = new ObjectPool(Factory); Assert.IsType(pool.Allocate()); } [Fact] public void TestAllocateFree() { - Func factory = () => new object(); - var pool = new ObjectPool(factory); + object Factory() => new object(); + var pool = new ObjectPool(Factory); // Covers the case where no item is in the pool Assert.IsType(pool.Allocate()); @@ -52,8 +52,8 @@ public void TestAllocateFree() [Fact] public void TestObjectCanBeDropped() { - Func factory = () => new object(); - var pool = new ObjectPool(factory, 1); + object Factory() => new object(); + var pool = new ObjectPool(Factory, 1); var obj = new object(); pool.Free(obj); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/ObjectPools/SharedPoolsTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/ObjectPools/SharedPoolsTests.cs index 9f2dfab7b..0583a8ad3 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/ObjectPools/SharedPoolsTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/ObjectPools/SharedPoolsTests.cs @@ -211,9 +211,14 @@ public void TestClearAndFreeLarge() [Fact] public void TestPooledObjectHandlesNullAllocation() { - Func, object> allocator = pool => null; - Action, object> releaser = (pool, obj) => { }; - using (var obj = new PooledObject(SharedPools.Default(), allocator, releaser)) + object Allocator(ObjectPool pool) + => null; + + void Releaser(ObjectPool pool, object obj) + { + } + + using (var obj = new PooledObject(SharedPools.Default(), Allocator, Releaser)) { Assert.Null(obj.Object); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1503UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1503UnitTests.cs index 4d82662c1..e5cf84b50 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1503UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1503UnitTests.cs @@ -544,7 +544,7 @@ public void Bar(int i) /// A representing the asynchronous unit test. [Theory] [MemberData(nameof(TestStatements))] - private async Task TestCodeFixForStatementAsync(string statementText) + public async Task TestCodeFixForStatementAsync(string statementText) { var expected = Diagnostic().WithLocation(7, 13); await VerifyCSharpFixAsync(this.GenerateTestStatement(statementText), expected, this.GenerateFixedTestStatement(statementText), CancellationToken.None).ConfigureAwait(false); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonArrayTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonArrayTests.cs index 05a7dadcc..d35fc36f7 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonArrayTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonArrayTests.cs @@ -26,7 +26,7 @@ public void TestConstructor() Assert.Equal(1, obj2[0].AsInteger); Assert.Equal("test2", obj2[1].AsString); - Assert.Throws("values", () => new JsonArray(default(JsonValue[]))); + Assert.Throws("values", () => new JsonArray(default)); } [Fact] diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonObjectTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonObjectTests.cs index 8a8fa92d7..ea355e19a 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonObjectTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonObjectTests.cs @@ -107,6 +107,8 @@ public void TestRename() Assert.Same(value, obj["y"].AsString); } +#pragma warning disable IDE0060 // Remove unused parameter private static Type StaticType(T value) => typeof(T); +#pragma warning restore IDE0060 // Remove unused parameter } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonValueTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonValueTests.cs index 5b155476a..148838f1f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonValueTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonValueTests.cs @@ -308,7 +308,7 @@ public void TestConversionOperators() [Fact] public void TestOpInequality() { - Assert.False(JsonValue.Null != default(JsonValue)); + Assert.False(JsonValue.Null != default); Assert.True(new JsonValue(true) != new JsonValue(0)); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Lightup/AutoWrapSeparatedSyntaxListTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Lightup/AutoWrapSeparatedSyntaxListTests.cs index 4f4f27372..4b672725f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Lightup/AutoWrapSeparatedSyntaxListTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Lightup/AutoWrapSeparatedSyntaxListTests.cs @@ -11,7 +11,7 @@ public class AutoWrapSeparatedSyntaxListTests : SeparatedSyntaxListWrapperTestBa { internal override SeparatedSyntaxListWrapper CreateList() { - return new SeparatedSyntaxListWrapper.AutoWrapSeparatedSyntaxList(default(SeparatedSyntaxList)); + return new SeparatedSyntaxListWrapper.AutoWrapSeparatedSyntaxList(default); } internal override bool TryCreateNonEmptyList(out SeparatedSyntaxListWrapper list) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1412UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1412UnitTests.cs index 0f6202231..9cd64607a 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1412UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1412UnitTests.cs @@ -110,6 +110,9 @@ public async Task TestFixAllWithMultipleEncodingsAsync() private async Task TestFixAllExecuterAsync(int codepage, FixAllScope scope) { + // Currently unused + _ = scope; + var test = new CSharpTest { TestSources = diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1200PreserveUnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1200PreserveUnitTests.cs index 3ca7e0649..d45e04e56 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1200PreserveUnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1200PreserveUnitTests.cs @@ -126,9 +126,6 @@ namespace TestNamespace await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); } - private static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor) - => StyleCopCodeFixVerifier.Diagnostic(descriptor); - private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { var test = new StyleCopCodeFixVerifier.CSharpTest @@ -140,18 +137,5 @@ private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[ test.ExpectedDiagnostics.AddRange(expected); return test.RunAsync(cancellationToken); } - - private static Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expected, string fixedSource, CancellationToken cancellationToken) - { - var test = new StyleCopCodeFixVerifier.CSharpTest - { - TestCode = source, - FixedCode = fixedSource, - Settings = TestSettings, - }; - - test.ExpectedDiagnostics.AddRange(expected); - return test.RunAsync(cancellationToken); - } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1116UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1116UnitTests.cs index 5fbfd0c2d..d541c708e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1116UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1116UnitTests.cs @@ -57,6 +57,10 @@ public static IEnumerable ValidTestExpressions() [MemberData(nameof(GetTestDeclarations), "", "")] public async Task TestValidDeclarationAsync(string declaration, string fixedDeclaration, int column) { + // Not needed for this test + _ = fixedDeclaration; + _ = column; + var testCode = $@" class Foo {{ @@ -87,6 +91,9 @@ class Foo [MemberData(nameof(GetTestConstructorInitializers), "", "")] public async Task TestValidConstructorInitializerAsync(string initializer, string fixedInitializer) { + // Not needed for this test + _ = fixedInitializer; + var testCode = $@" class Base {{ @@ -165,6 +172,10 @@ public Derived(int i, string z) [MemberData(nameof(ValidTestExpressions))] public async Task TestValidExpressionAsync(string expression, string fixedExpression, int column) { + // Not needed for this test + _ = fixedExpression; + _ = column; + var testCode = $@" class Foo {{ diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1117UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1117UnitTests.cs index 490c6687b..db1f65339 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1117UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1117UnitTests.cs @@ -156,6 +156,9 @@ public Derived(int i, int j, string z) [MemberData(nameof(ValidTestExpressions))] public async Task TestValidExpressionAsync(string expression, int column) { + // Not needed for this test + _ = column; + var testCode = $@" class Foo {{ @@ -178,6 +181,9 @@ public void Baz() [MemberData(nameof(GetTestExpressions), "\r\n")] public async Task TestInvalidExpressionAsync(string expression, int column) { + // Not needed for this test + _ = column; + var testCode = $@" class Foo {{ diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1121UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1121UnitTests.cs index 6273b8fd4..354c16bfe 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1121UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1121UnitTests.cs @@ -668,6 +668,9 @@ public class Bar {{ }} [MemberData(nameof(AllTypes))] public async Task TestNameOfAsync(string predefined, string fullName) { + // Not needed for this test + _ = predefined; + string testCode = @" namespace System {{ diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs index 4faf040fc..21454bca2 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs @@ -386,7 +386,7 @@ public AdditionalTextHelper(string path, string text) public override string Path { get; } - public override SourceText GetText(CancellationToken cancellationToken = default(CancellationToken)) + public override SourceText GetText(CancellationToken cancellationToken = default) { return this.sourceText; } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/FileHeaderAnalyzers.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/FileHeaderAnalyzers.cs index f164d8028..6f3101607 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/FileHeaderAnalyzers.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/FileHeaderAnalyzers.cs @@ -222,7 +222,7 @@ public static void HandleSyntaxTree(SyntaxTreeAnalysisContext context, StyleCopS if (!compilation.IsAnalyzerSuppressed(SA1639Descriptor)) { - CheckSummaryHeader(context, compilation, fileHeader); + CheckSummaryHeader(context, fileHeader); } } else @@ -363,7 +363,7 @@ private static void CheckCompanyName(SyntaxTreeAnalysisContext context, Document } } - private static void CheckSummaryHeader(SyntaxTreeAnalysisContext context, Compilation compilation, XmlFileHeader fileHeader) + private static void CheckSummaryHeader(SyntaxTreeAnalysisContext context, XmlFileHeader fileHeader) { var summaryElement = fileHeader.GetElement("summary"); if (summaryElement == null) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PartialElementDocumentationSummaryBase.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PartialElementDocumentationSummaryBase.cs index 554cfbbe5..3931fe36b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PartialElementDocumentationSummaryBase.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PartialElementDocumentationSummaryBase.cs @@ -21,8 +21,6 @@ namespace StyleCop.Analyzers.DocumentationRules /// internal abstract class PartialElementDocumentationSummaryBase : DiagnosticAnalyzer { - private static readonly XElement EmptyElement = new XElement("empty"); - private readonly Action typeDeclarationAction; private readonly Action methodDeclarationAction; @@ -170,8 +168,6 @@ private string ExpandDocumentation(Compilation compilation, DocumentationComment sb.AppendLine(""); - var documentationChildren = new List(); - foreach (XmlNodeSyntax xmlNode in documentCommentTrivia.Content) { if (xmlNode == includeTag) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1643DestructorSummaryDocumentationMustBeginWithStandardText.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1643DestructorSummaryDocumentationMustBeginWithStandardText.cs index 9e02662b5..05a047152 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1643DestructorSummaryDocumentationMustBeginWithStandardText.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1643DestructorSummaryDocumentationMustBeginWithStandardText.cs @@ -78,7 +78,6 @@ public override void Initialize(AnalysisContext context) private static void HandleDestructor(SyntaxNodeAnalysisContext context) { - var destructorDeclaration = (DestructorDeclarationSyntax)context.Node; var settings = context.Options.GetStyleCopSettings(context.CancellationToken); var culture = new CultureInfo(settings.DocumentationRules.DocumentationCulture); var resourceManager = DocumentationResources.ResourceManager; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/AccessLevelHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/AccessLevelHelper.cs index 1737cc53a..05c45de30 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/AccessLevelHelper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/AccessLevelHelper.cs @@ -292,13 +292,18 @@ internal static Accessibility GetDeclaredAccessibility(this BaseFieldDeclaration return declaredSymbol?.DeclaredAccessibility ?? Accessibility.NotApplicable; } +#pragma warning disable IDE0060 // Remove unused parameter - false positive internal static Accessibility GetDeclaredAccessibility(this EnumMemberDeclarationSyntax syntax) { return Accessibility.Public; } +#pragma warning restore IDE0060 // Remove unused parameter internal static Accessibility GetDeclaredAccessibility(this DelegateDeclarationSyntax syntax, SemanticModel semanticModel, CancellationToken cancellationToken) { + // Currently unused + _ = cancellationToken; + Requires.NotNull(syntax, nameof(syntax)); Requires.NotNull(semanticModel, nameof(semanticModel)); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/DeclarationModifiersHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/DeclarationModifiersHelper.cs index 90801515e..3b95ff309 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/DeclarationModifiersHelper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/DeclarationModifiersHelper.cs @@ -122,7 +122,7 @@ internal static SyntaxTokenList GetModifiers(this MemberDeclarationSyntax syntax return ((IncompleteMemberSyntax)syntax).Modifiers; } - return default(SyntaxTokenList); + return default; } internal static SyntaxNode WithModifiers(this SyntaxNode node, SyntaxTokenList modifiers) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/FileHeader.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/FileHeader.cs index 143844493..63b6618dc 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/FileHeader.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/FileHeader.cs @@ -12,7 +12,6 @@ namespace StyleCop.Analyzers.Helpers internal class FileHeader { private readonly int fileHeaderStart; - private readonly int fileHeaderEnd; /// /// Initializes a new instance of the class. @@ -22,9 +21,11 @@ internal class FileHeader /// The offset within the file at which the header ended. internal FileHeader(string copyrightText, int fileHeaderStart, int fileHeaderEnd) { + // Currently unused + _ = fileHeaderEnd; + this.CopyrightText = copyrightText; this.fileHeaderStart = fileHeaderStart; - this.fileHeaderEnd = fileHeaderEnd; } /// diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/XmlCommentHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/XmlCommentHelper.cs index cc73116c6..b03e45a6e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/XmlCommentHelper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/XmlCommentHelper.cs @@ -122,18 +122,13 @@ internal static bool IsConsideredEmpty(XmlNodeSyntax xmlSyntax, bool considerEmp return true; } - if (xmlSyntax is XmlEmptyElementSyntax emptyElement) + if (xmlSyntax is XmlEmptyElementSyntax) { // This includes return considerEmptyElements; } - if (xmlSyntax is XmlProcessingInstructionSyntax processingElement) - { - return false; - } - - return true; + return !(xmlSyntax is XmlProcessingInstructionSyntax); } /// @@ -162,12 +157,7 @@ internal static bool IsConsideredEmpty(XNode node) return true; } - if (node is XProcessingInstruction processingElement) - { - return false; - } - - return true; + return !(node is XProcessingInstruction); } /// diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1501StatementMustNotBeOnASingleLine.cs b/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1501StatementMustNotBeOnASingleLine.cs index 2e661f92b..b5f1c10cd 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1501StatementMustNotBeOnASingleLine.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1501StatementMustNotBeOnASingleLine.cs @@ -85,13 +85,13 @@ private static void HandleCompilationStart(CompilationStartAnalysisContext conte if (context.IsAnalyzerSuppressed(SA1503BracesMustNotBeOmitted.Descriptor)) { context.RegisterSyntaxNodeAction(HandleIfStatement, SyntaxKind.IfStatement); - context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((DoStatementSyntax)ctx.Node).Statement), SyntaxKind.DoStatement); - context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((WhileStatementSyntax)ctx.Node).Statement), SyntaxKind.WhileStatement); - context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((ForStatementSyntax)ctx.Node).Statement), SyntaxKind.ForStatement); - context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((ForEachStatementSyntax)ctx.Node).Statement), SyntaxKind.ForEachStatement); - context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((LockStatementSyntax)ctx.Node).Statement), SyntaxKind.LockStatement); - context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((UsingStatementSyntax)ctx.Node).Statement), SyntaxKind.UsingStatement); - context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((FixedStatementSyntax)ctx.Node).Statement), SyntaxKind.FixedStatement); + context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ((DoStatementSyntax)ctx.Node).Statement), SyntaxKind.DoStatement); + context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ((WhileStatementSyntax)ctx.Node).Statement), SyntaxKind.WhileStatement); + context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ((ForStatementSyntax)ctx.Node).Statement), SyntaxKind.ForStatement); + context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ((ForEachStatementSyntax)ctx.Node).Statement), SyntaxKind.ForEachStatement); + context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ((LockStatementSyntax)ctx.Node).Statement), SyntaxKind.LockStatement); + context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ((UsingStatementSyntax)ctx.Node).Statement), SyntaxKind.UsingStatement); + context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ((FixedStatementSyntax)ctx.Node).Statement), SyntaxKind.FixedStatement); } } @@ -157,17 +157,11 @@ private static void HandleIfStatement(SyntaxNodeAnalysisContext context) foreach (StatementSyntax clause in clauses) { - SyntaxNode node = clause.Parent; - if (node.IsKind(SyntaxKind.IfStatement) && node.Parent.IsKind(SyntaxKind.ElseClause)) - { - node = node.Parent; - } - - CheckChildStatement(context, node, clause); + CheckChildStatement(context, clause); } } - private static void CheckChildStatement(SyntaxNodeAnalysisContext context, SyntaxNode node, StatementSyntax childStatement) + private static void CheckChildStatement(SyntaxNodeAnalysisContext context, StatementSyntax childStatement) { bool reportAsHidden = false; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1509OpeningBracesMustNotBePrecededByBlankLine.cs b/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1509OpeningBracesMustNotBePrecededByBlankLine.cs index a2c20aa50..99ec55d97 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1509OpeningBracesMustNotBePrecededByBlankLine.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1509OpeningBracesMustNotBePrecededByBlankLine.cs @@ -72,7 +72,7 @@ private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context) { var syntaxRoot = context.Tree.GetRoot(context.CancellationToken); - SyntaxToken previousToken = default(SyntaxToken); + SyntaxToken previousToken = default; foreach (var token in syntaxRoot.DescendantTokens()) { if (token.IsKind(SyntaxKind.OpenBraceToken) && !previousToken.IsKind(SyntaxKind.CloseBraceToken)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1516ElementsMustBeSeparatedByBlankLine.cs b/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1516ElementsMustBeSeparatedByBlankLine.cs index 8e22b8093..172518396 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1516ElementsMustBeSeparatedByBlankLine.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1516ElementsMustBeSeparatedByBlankLine.cs @@ -204,8 +204,6 @@ private static void HandleCompilationUnit(SyntaxNodeAnalysisContext context, Sty { ReportIfThereIsNoBlankLine(context, previousItem, members[0]); } - - previousItem = members.Last(); } } @@ -369,7 +367,7 @@ private static Location GetDiagnosticLocation(SyntaxNode node) } var firstToken = node.ChildTokens().FirstOrDefault(); - if (firstToken != default(SyntaxToken)) + if (firstToken != default) { return node.ChildTokens().First().GetLocation(); } @@ -381,7 +379,7 @@ private static bool HasEmptyLine(IEnumerable allTrivia) { allTrivia = allTrivia.Where(x => !x.IsKind(SyntaxKind.WhitespaceTrivia)); - SyntaxTrivia previousTrivia = default(SyntaxTrivia); + SyntaxTrivia previousTrivia = default; foreach (var trivia in allTrivia) { diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1518UseLineEndingsCorrectlyAtEndOfFile.cs b/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1518UseLineEndingsCorrectlyAtEndOfFile.cs index 897a9d27b..111b607af 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1518UseLineEndingsCorrectlyAtEndOfFile.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1518UseLineEndingsCorrectlyAtEndOfFile.cs @@ -68,7 +68,7 @@ private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context, StyleCop var endOfFileToken = context.Tree.GetRoot().GetLastToken(includeZeroWidth: true); TextSpan reportedSpan = new TextSpan(endOfFileToken.SpanStart, 0); - SyntaxTrivia precedingTrivia = default(SyntaxTrivia); + SyntaxTrivia precedingTrivia = default; bool checkPrecedingToken; if (endOfFileToken.HasLeadingTrivia) { @@ -108,7 +108,7 @@ private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context, StyleCop else if (trailingWhitespaceIndex == 0) { reportedSpan = TextSpan.FromBounds(previousToken.TrailingTrivia[trailingWhitespaceIndex].SpanStart, reportedSpan.End); - precedingTrivia = default(SyntaxTrivia); + precedingTrivia = default; } else { diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonObject.cs b/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonObject.cs index c41a97ce7..771b3ad4e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonObject.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonObject.cs @@ -217,8 +217,10 @@ public KeyValuePair[] Keys [DebuggerDisplay("{value.ToString(),nq}", Name = "{key}", Type = "JsonValue({Type})")] public class KeyValuePair { +#pragma warning disable IDE0052 // Remove unread private members [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly string key; +#pragma warning restore IDE0052 // Remove unread private members [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly JsonValue value; @@ -248,15 +250,6 @@ public object View } } } - - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private JsonValueType Type - { - get - { - return this.value.Type; - } - } } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonValue.cs b/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonValue.cs index 366dcbdae..b9029d7f1 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonValue.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonValue.cs @@ -20,7 +20,7 @@ internal struct JsonValue /// /// Represents a null JsonValue. /// - public static readonly JsonValue Null = new JsonValue(JsonValueType.Null, default(double), null); + public static readonly JsonValue Null = new JsonValue(JsonValueType.Null, default, null); private readonly JsonValueType type; private readonly object reference; @@ -74,7 +74,7 @@ public JsonValue(string value) { if (value != null) { - this.value = default(double); + this.value = default; this.type = JsonValueType.String; @@ -94,7 +94,7 @@ public JsonValue(JsonObject value) { if (value != null) { - this.value = default(double); + this.value = default; this.type = JsonValueType.Object; @@ -114,7 +114,7 @@ public JsonValue(JsonArray value) { if (value != null) { - this.value = default(double); + this.value = default; this.type = JsonValueType.Array; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/Serialization/JsonWriter.cs b/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/Serialization/JsonWriter.cs index 0b6c47dac..5e487bd1d 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/Serialization/JsonWriter.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/Serialization/JsonWriter.cs @@ -107,11 +107,6 @@ public void Dispose() } } - private static bool IsValidNumber(double number) - { - return !(double.IsNaN(number) || double.IsInfinity(number)); - } - private void Initialize() { this.indent = 0; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CasePatternSwitchLabelSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CasePatternSwitchLabelSyntaxWrapper.cs index 1cffd13a6..8e1a3cd25 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CasePatternSwitchLabelSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CasePatternSwitchLabelSyntaxWrapper.cs @@ -60,7 +60,7 @@ public static explicit operator CasePatternSwitchLabelSyntaxWrapper(SyntaxNode n { if (node == null) { - return default(CasePatternSwitchLabelSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CommonForEachStatementSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CommonForEachStatementSyntaxWrapper.cs index 4bb3641d4..7cd9719e6 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CommonForEachStatementSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CommonForEachStatementSyntaxWrapper.cs @@ -97,7 +97,7 @@ public static explicit operator CommonForEachStatementSyntaxWrapper(SyntaxNode n { if (node == null) { - return default(CommonForEachStatementSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ConstantPatternSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ConstantPatternSyntaxWrapper.cs index 5509d924d..54254e9dd 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ConstantPatternSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ConstantPatternSyntaxWrapper.cs @@ -49,7 +49,7 @@ public static explicit operator ConstantPatternSyntaxWrapper(SyntaxNode node) { if (node == null) { - return default(ConstantPatternSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationExpressionSyntaxWrapper.cs index 9695671e8..c4d33f692 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationExpressionSyntaxWrapper.cs @@ -56,7 +56,7 @@ public static explicit operator DeclarationExpressionSyntaxWrapper(SyntaxNode no { if (node == null) { - return default(DeclarationExpressionSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationPatternSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationPatternSyntaxWrapper.cs index 3c8d334ab..c92ba2782 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationPatternSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationPatternSyntaxWrapper.cs @@ -61,7 +61,7 @@ public static explicit operator DeclarationPatternSyntaxWrapper(SyntaxNode node) { if (node == null) { - return default(DeclarationPatternSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DiscardDesignationSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DiscardDesignationSyntaxWrapper.cs index 59f79e09c..39a17c6f6 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DiscardDesignationSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DiscardDesignationSyntaxWrapper.cs @@ -48,7 +48,7 @@ public static explicit operator DiscardDesignationSyntaxWrapper(SyntaxNode node) { if (node == null) { - return default(DiscardDesignationSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ForEachVariableStatementSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ForEachVariableStatementSyntaxWrapper.cs index 4c3a11bc9..12df8da3f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ForEachVariableStatementSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ForEachVariableStatementSyntaxWrapper.cs @@ -108,7 +108,7 @@ public static explicit operator ForEachVariableStatementSyntaxWrapper(SyntaxNode { if (node == null) { - return default(ForEachVariableStatementSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.cs index 21686f6de..9148938b8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.cs @@ -79,7 +79,7 @@ public static explicit operator ImplicitStackAllocArrayCreationExpressionSyntaxW { if (node == null) { - return default(ImplicitStackAllocArrayCreationExpressionSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/IsPatternExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/IsPatternExpressionSyntaxWrapper.cs index 7e1e80d8d..c74d219df 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/IsPatternExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/IsPatternExpressionSyntaxWrapper.cs @@ -68,7 +68,7 @@ public static explicit operator IsPatternExpressionSyntaxWrapper(SyntaxNode node { if (node == null) { - return default(IsPatternExpressionSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs index 0edafd2b6..4c3e8e9c9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs @@ -58,22 +58,21 @@ internal static bool CanWrapNode(SyntaxNode node, Type underlyingType) internal static Func CreateSyntaxPropertyAccessor(Type type, string propertyName) { - Func fallbackAccessor = - syntax => + TProperty FallbackAccessor(TSyntax syntax) + { + if (syntax == null) { - if (syntax == null) - { - // Unlike an extension method which would throw ArgumentNullException here, the light-up - // behavior needs to match behavior of the underlying property. - throw new NullReferenceException(); - } + // Unlike an extension method which would throw ArgumentNullException here, the light-up + // behavior needs to match behavior of the underlying property. + throw new NullReferenceException(); + } - return default(TProperty); - }; + return default; + } if (type == null) { - return fallbackAccessor; + return FallbackAccessor; } if (!typeof(TSyntax).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo())) @@ -84,7 +83,7 @@ internal static Func CreateSyntaxPropertyAccessor CreateSyntaxPropertyAccessor> CreateSeparatedSyntaxListPropertyAccessor(Type type, string propertyName) { - Func> fallbackAccessor = - syntax => + SeparatedSyntaxListWrapper FallbackAccessor(TSyntax syntax) + { + if (syntax == null) { - if (syntax == null) - { - // Unlike an extension method which would throw ArgumentNullException here, the light-up - // behavior needs to match behavior of the underlying property. - throw new NullReferenceException(); - } + // Unlike an extension method which would throw ArgumentNullException here, the light-up + // behavior needs to match behavior of the underlying property. + throw new NullReferenceException(); + } - return SeparatedSyntaxListWrapper.UnsupportedEmpty; - }; + return SeparatedSyntaxListWrapper.UnsupportedEmpty; + } if (type == null) { - return fallbackAccessor; + return FallbackAccessor; } if (!typeof(TSyntax).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo())) @@ -133,7 +131,7 @@ internal static Func> CreateSepar var property = type.GetTypeInfo().GetDeclaredProperty(propertyName); if (property == null) { - return fallbackAccessor; + return FallbackAccessor; } if (property.PropertyType.GetGenericTypeDefinition() != typeof(SeparatedSyntaxList<>)) @@ -168,27 +166,26 @@ internal static Func> CreateSepar internal static Func CreateSyntaxWithPropertyAccessor(Type type, string propertyName) { - Func fallbackAccessor = - (syntax, newValue) => + TSyntax FallbackAccessor(TSyntax syntax, TProperty newValue) + { + if (syntax == null) { - if (syntax == null) - { - // Unlike an extension method which would throw ArgumentNullException here, the light-up - // behavior needs to match behavior of the underlying property. - throw new NullReferenceException(); - } + // Unlike an extension method which would throw ArgumentNullException here, the light-up + // behavior needs to match behavior of the underlying property. + throw new NullReferenceException(); + } - if (Equals(newValue, default(TProperty))) - { - return syntax; - } + if (Equals(newValue, default(TProperty))) + { + return syntax; + } - throw new NotSupportedException(); - }; + throw new NotSupportedException(); + } if (type == null) { - return fallbackAccessor; + return FallbackAccessor; } if (!typeof(TSyntax).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo())) @@ -199,7 +196,7 @@ internal static Func CreateSyntaxWithPropertyAccess var property = type.GetTypeInfo().GetDeclaredProperty(propertyName); if (property == null) { - return fallbackAccessor; + return FallbackAccessor; } if (!typeof(TProperty).GetTypeInfo().IsAssignableFrom(property.PropertyType.GetTypeInfo())) @@ -231,27 +228,26 @@ internal static Func CreateSyntaxWithPropertyAccess internal static Func, TSyntax> CreateSeparatedSyntaxListWithPropertyAccessor(Type type, string propertyName) { - Func, TSyntax> fallbackAccessor = - (syntax, newValue) => + TSyntax FallbackAccessor(TSyntax syntax, SeparatedSyntaxListWrapper newValue) + { + if (syntax == null) { - if (syntax == null) - { - // Unlike an extension method which would throw ArgumentNullException here, the light-up - // behavior needs to match behavior of the underlying property. - throw new NullReferenceException(); - } + // Unlike an extension method which would throw ArgumentNullException here, the light-up + // behavior needs to match behavior of the underlying property. + throw new NullReferenceException(); + } - if (newValue is null) - { - return syntax; - } + if (newValue is null) + { + return syntax; + } - throw new NotSupportedException(); - }; + throw new NotSupportedException(); + } if (type == null) { - return fallbackAccessor; + return FallbackAccessor; } if (!typeof(TSyntax).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo())) @@ -262,7 +258,7 @@ internal static Func, TSyntax> Cr var property = type.GetTypeInfo().GetDeclaredProperty(propertyName); if (property == null) { - return fallbackAccessor; + return FallbackAccessor; } if (property.PropertyType.GetGenericTypeDefinition() != typeof(SeparatedSyntaxList<>)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LocalFunctionStatementSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LocalFunctionStatementSyntaxWrapper.cs index 4df1bbe3e..8ffa5d21e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LocalFunctionStatementSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LocalFunctionStatementSyntaxWrapper.cs @@ -140,7 +140,7 @@ public static explicit operator LocalFunctionStatementSyntaxWrapper(SyntaxNode n { if (node == null) { - return default(LocalFunctionStatementSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ParenthesizedVariableDesignationSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ParenthesizedVariableDesignationSyntaxWrapper.cs index fc3d04895..57a528997 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ParenthesizedVariableDesignationSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ParenthesizedVariableDesignationSyntaxWrapper.cs @@ -72,7 +72,7 @@ public static explicit operator ParenthesizedVariableDesignationSyntaxWrapper(Sy { if (node == null) { - return default(ParenthesizedVariableDesignationSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PatternSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PatternSyntaxWrapper.cs index 237b3ad1c..a1c48ed2d 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PatternSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PatternSyntaxWrapper.cs @@ -30,7 +30,7 @@ public static explicit operator PatternSyntaxWrapper(SyntaxNode node) { if (node == null) { - return default(PatternSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefExpressionSyntaxWrapper.cs index 0dfe1b24a..c6838f1cb 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefExpressionSyntaxWrapper.cs @@ -55,7 +55,7 @@ public static explicit operator RefExpressionSyntaxWrapper(SyntaxNode node) { if (node == null) { - return default(RefExpressionSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefTypeSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefTypeSyntaxWrapper.cs index 5e3c1888b..6828db891 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefTypeSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefTypeSyntaxWrapper.cs @@ -67,7 +67,7 @@ public static explicit operator RefTypeSyntaxWrapper(SyntaxNode node) { if (node == null) { - return default(RefTypeSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SeparatedSyntaxListWrapper`1.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SeparatedSyntaxListWrapper`1.cs index 631eb3b85..fb75f1d16 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SeparatedSyntaxListWrapper`1.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SeparatedSyntaxListWrapper`1.cs @@ -52,11 +52,19 @@ public abstract TNode this[int index] public static bool operator ==(SeparatedSyntaxListWrapper left, SeparatedSyntaxListWrapper right) { + // Currently unused + _ = left; + _ = right; + throw new NotImplementedException(); } public static bool operator !=(SeparatedSyntaxListWrapper left, SeparatedSyntaxListWrapper right) { + // Currently unused + _ = left; + _ = right; + throw new NotImplementedException(); } @@ -159,7 +167,7 @@ public Enumerator(SeparatedSyntaxListWrapper wrapper) { this.wrapper = wrapper; this.index = -1; - this.current = default(TNode); + this.current = default; } public TNode Current => this.current; @@ -214,7 +222,7 @@ public bool MoveNext() public void Reset() { this.index = -1; - this.current = default(TNode); + this.current = default; } } @@ -323,7 +331,7 @@ public override string ToString() private sealed class UnsupportedSyntaxList : SeparatedSyntaxListWrapper { - private static readonly SeparatedSyntaxList SyntaxList = default(SeparatedSyntaxList); + private static readonly SeparatedSyntaxList SyntaxList = default; public UnsupportedSyntaxList() { @@ -357,7 +365,7 @@ public override TNode First() => SyntaxWrapper.Wrap(SyntaxList.First()); public override TNode FirstOrDefault() - => SyntaxWrapper.Wrap(default(SyntaxNode)); + => SyntaxWrapper.Wrap(default); public override int GetHashCode() => SyntaxList.GetHashCode(); @@ -397,7 +405,7 @@ public override int LastIndexOf(Func predicate) => SyntaxList.LastIndexOf(node => predicate(SyntaxWrapper.Wrap(node))); public override TNode LastOrDefault() - => SyntaxWrapper.Wrap(default(SyntaxNode)); + => SyntaxWrapper.Wrap(default); public override SeparatedSyntaxListWrapper Remove(TNode node) { diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SingleVariableDesignationSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SingleVariableDesignationSyntaxWrapper.cs index aebb7bef2..b0366c8f2 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SingleVariableDesignationSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SingleVariableDesignationSyntaxWrapper.cs @@ -48,7 +48,7 @@ public static explicit operator SingleVariableDesignationSyntaxWrapper(SyntaxNod { if (node == null) { - return default(SingleVariableDesignationSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxFactsEx.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxFactsEx.cs index 65bc14bae..f1f576091 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxFactsEx.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxFactsEx.cs @@ -16,18 +16,17 @@ internal static class SyntaxFactsEx static SyntaxFactsEx() { - Func fallbackAccessor = - syntax => + string FallbackAccessor(SyntaxNode syntax) + { + if (syntax == null) { - if (syntax == null) - { - // Unlike an extension method which would throw ArgumentNullException here, the light-up - // behavior needs to match behavior of the underlying property. - throw new NullReferenceException(); - } + // Unlike an extension method which would throw ArgumentNullException here, the light-up + // behavior needs to match behavior of the underlying property. + throw new NullReferenceException(); + } - return null; - }; + return null; + } var tryGetInferredMemberNameMethod = typeof(SyntaxFacts).GetTypeInfo().GetDeclaredMethod(nameof(TryGetInferredMemberName)); if (tryGetInferredMemberNameMethod is object) @@ -41,7 +40,7 @@ static SyntaxFactsEx() } else { - TryGetInferredMemberNameAccessor = fallbackAccessor; + TryGetInferredMemberNameAccessor = FallbackAccessor; } var isReservedTupleElementNameMethod = typeof(SyntaxFacts).GetTypeInfo().GetDeclaredMethod(nameof(IsReservedTupleElementName)); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ThrowExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ThrowExpressionSyntaxWrapper.cs index 257615e4b..5fd5db5c2 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ThrowExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ThrowExpressionSyntaxWrapper.cs @@ -55,7 +55,7 @@ public static explicit operator ThrowExpressionSyntaxWrapper(SyntaxNode node) { if (node == null) { - return default(ThrowExpressionSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleElementSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleElementSyntaxWrapper.cs index 462373ead..cbea2e799 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleElementSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleElementSyntaxWrapper.cs @@ -56,7 +56,7 @@ public static explicit operator TupleElementSyntaxWrapper(SyntaxNode node) { if (node == null) { - return default(TupleElementSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleExpressionSyntaxWrapper.cs index 7f92f01d7..99d82b43a 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleExpressionSyntaxWrapper.cs @@ -67,7 +67,7 @@ public static explicit operator TupleExpressionSyntaxWrapper(SyntaxNode node) { if (node == null) { - return default(TupleExpressionSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleTypeSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleTypeSyntaxWrapper.cs index a1075b15b..a7498c564 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleTypeSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleTypeSyntaxWrapper.cs @@ -67,7 +67,7 @@ public static explicit operator TupleTypeSyntaxWrapper(SyntaxNode node) { if (node == null) { - return default(TupleTypeSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/VariableDesignationSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/VariableDesignationSyntaxWrapper.cs index 4db9302d2..6cbef54f0 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/VariableDesignationSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/VariableDesignationSyntaxWrapper.cs @@ -30,7 +30,7 @@ public static explicit operator VariableDesignationSyntaxWrapper(SyntaxNode node { if (node == null) { - return default(VariableDesignationSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/WhenClauseSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/WhenClauseSyntaxWrapper.cs index 4b5f593f3..89250062d 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/WhenClauseSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/WhenClauseSyntaxWrapper.cs @@ -56,7 +56,7 @@ public static explicit operator WhenClauseSyntaxWrapper(SyntaxNode node) { if (node == null) { - return default(WhenClauseSyntaxWrapper); + return default; } if (!IsInstance(node)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/LinqHelpers/SyntaxTriviaListEnumerable.cs b/StyleCop.Analyzers/StyleCop.Analyzers/LinqHelpers/SyntaxTriviaListEnumerable.cs index 11f63ded8..74e228234 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/LinqHelpers/SyntaxTriviaListEnumerable.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/LinqHelpers/SyntaxTriviaListEnumerable.cs @@ -113,7 +113,7 @@ internal static SyntaxTrivia LastOrDefault(this SyntaxTriviaList list, SyntaxKin } } - return default(SyntaxTrivia); + return default; } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs b/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs index 9c3af4e15..ac221a6f4 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs @@ -161,7 +161,7 @@ private static void HandleParenthesizedExpression(SyntaxNodeAnalysisContext cont } else { - if (node.Parent is AssignmentExpressionSyntax assignValue) + if (node.Parent is AssignmentExpressionSyntax) { ReportDiagnostic(context, node); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1412StoreFilesAsUtf8.cs b/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1412StoreFilesAsUtf8.cs index 52ec35b82..77890d0ce 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1412StoreFilesAsUtf8.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1412StoreFilesAsUtf8.cs @@ -39,7 +39,7 @@ internal class SA1412StoreFilesAsUtf8 : DiagnosticAnalyzer private static readonly Action SyntaxTreeAction = HandleSyntaxTree; - private static byte[] utf8Preamble = Encoding.UTF8.GetPreamble(); + private static readonly byte[] Utf8Preamble = Encoding.UTF8.GetPreamble(); /// /// Gets the key for the detected encoding name in the collection. @@ -81,15 +81,15 @@ private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context) private static bool IsUtf8Preamble(byte[] preamble) { - if (preamble == null || preamble.Length != utf8Preamble.Length) + if (preamble == null || preamble.Length != Utf8Preamble.Length) { return false; } else { - for (int i = 0; i < utf8Preamble.Length; i++) + for (int i = 0; i < Utf8Preamble.Length; i++) { - if (utf8Preamble[i] != preamble[i]) + if (Utf8Preamble[i] != preamble[i]) { return false; } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1303ConstFieldNamesMustBeginWithUpperCaseLetter.cs b/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1303ConstFieldNamesMustBeginWithUpperCaseLetter.cs index 9f4399df9..3ad86a7a2 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1303ConstFieldNamesMustBeginWithUpperCaseLetter.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1303ConstFieldNamesMustBeginWithUpperCaseLetter.cs @@ -51,7 +51,7 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); - context.RegisterSymbolAction(Analyzer.HandleFieldDeclaration, SymbolKind.Field); + context.RegisterSymbolAction(FieldDeclarationAction, SymbolKind.Field); } private static class Analyzer diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1316TupleElementNamesShouldUseCorrectCasing.cs b/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1316TupleElementNamesShouldUseCorrectCasing.cs index 166adf637..58f385a1e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1316TupleElementNamesShouldUseCorrectCasing.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1316TupleElementNamesShouldUseCorrectCasing.cs @@ -108,7 +108,7 @@ private static void CheckName(SyntaxNodeAnalysisContext context, StyleCopSetting { var firstCharacterIsLower = char.IsLower(tupleElementName[0]); - bool reportDiagnostic = false; + bool reportDiagnostic; string fixedName; switch (settings.NamingRules.TupleElementNameCasing) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1202ElementsMustBeOrderedByAccess.cs b/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1202ElementsMustBeOrderedByAccess.cs index 6ab2c7b26..871d89071 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1202ElementsMustBeOrderedByAccess.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1202ElementsMustBeOrderedByAccess.cs @@ -98,7 +98,7 @@ private static void HandleCompilationUnit(SyntaxNodeAnalysisContext context, Sty var compilationUnit = (CompilationUnitSyntax)context.Node; - HandleMemberList(context, elementOrder, accessibilityIndex, compilationUnit.Members, AccessLevel.Internal); + HandleMemberList(context, elementOrder, accessibilityIndex, compilationUnit.Members); } private static void HandleNamespaceDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings) @@ -112,7 +112,7 @@ private static void HandleNamespaceDeclaration(SyntaxNodeAnalysisContext context var compilationUnit = (NamespaceDeclarationSyntax)context.Node; - HandleMemberList(context, elementOrder, accessibilityIndex, compilationUnit.Members, AccessLevel.Internal); + HandleMemberList(context, elementOrder, accessibilityIndex, compilationUnit.Members); } private static void HandleTypeDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings) @@ -126,12 +126,11 @@ private static void HandleTypeDeclaration(SyntaxNodeAnalysisContext context, Sty var typeDeclaration = (TypeDeclarationSyntax)context.Node; - HandleMemberList(context, elementOrder, accessibilityIndex, typeDeclaration.Members, AccessLevel.Private); + HandleMemberList(context, elementOrder, accessibilityIndex, typeDeclaration.Members); } - private static void HandleMemberList(SyntaxNodeAnalysisContext context, ImmutableArray elementOrder, int accessibilityIndex, SyntaxList members, AccessLevel defaultAccessLevel) + private static void HandleMemberList(SyntaxNodeAnalysisContext context, ImmutableArray elementOrder, int accessibilityIndex, SyntaxList members) { - MemberDeclarationSyntax previousMember = null; var previousSyntaxKind = SyntaxKind.None; var previousAccessLevel = AccessLevel.NotSpecified; bool previousIsConst = false; @@ -212,7 +211,6 @@ private static void HandleMemberList(SyntaxNodeAnalysisContext context, Immutabl } } - previousMember = member; previousSyntaxKind = currentSyntaxKind; previousAccessLevel = currentAccessLevel; previousIsConst = currentIsConst; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1206DeclarationKeywordsMustFollowOrder.cs b/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1206DeclarationKeywordsMustFollowOrder.cs index da8e99571..b22a9cce1 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1206DeclarationKeywordsMustFollowOrder.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1206DeclarationKeywordsMustFollowOrder.cs @@ -88,8 +88,8 @@ private static void CheckModifiersOrderAndReportDiagnostics(SyntaxNodeAnalysisCo { var previousModifierType = ModifierType.None; var otherModifiersAppearEarlier = false; - SyntaxToken previousModifier = default(SyntaxToken); - SyntaxToken previousOtherModifier = default(SyntaxToken); + SyntaxToken previousModifier = default; + SyntaxToken previousOtherModifier = default; foreach (var modifier in modifiers) { @@ -155,28 +155,6 @@ private static int CompareModifiersType(ModifierType first, ModifierType second) return result; } - private static string GetModifierTypeText(ModifierType modifierType) - { - var result = string.Empty; - - switch (modifierType) - { - case ModifierType.Access: - result = "access modifier"; - break; - - case ModifierType.Static: - result = "static"; - break; - - case ModifierType.Other: - result = "other"; - break; - } - - return result; - } - private static bool AccessOrStaticModifierNotFollowingOtherModifier(ModifierType current, ModifierType previous) => (current == ModifierType.Access || current == ModifierType.Static) && previous != ModifierType.Other; } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1115ParameterMustFollowComma.cs b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1115ParameterMustFollowComma.cs index cb9a90200..c3e44ec2f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1115ParameterMustFollowComma.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1115ParameterMustFollowComma.cs @@ -138,7 +138,7 @@ private static void HandleParenthesizedLambdaExpression(SyntaxNodeAnalysisContex private static void HandleAnonymousMethodExpression(SyntaxNodeAnalysisContext context) { var anonymousMethod = (AnonymousMethodExpressionSyntax)context.Node; - AnalyzeSyntaxList(context, anonymousMethod.ParameterList?.Parameters ?? default(SeparatedSyntaxList)); + AnalyzeSyntaxList(context, anonymousMethod.ParameterList?.Parameters ?? default); } private static void HandleAttributeList(SyntaxNodeAnalysisContext context) @@ -150,7 +150,7 @@ private static void HandleAttributeList(SyntaxNodeAnalysisContext context) private static void HandleAttribute(SyntaxNodeAnalysisContext context) { var attribute = (AttributeSyntax)context.Node; - AnalyzeSyntaxList(context, attribute.ArgumentList?.Arguments ?? default(SeparatedSyntaxList)); + AnalyzeSyntaxList(context, attribute.ArgumentList?.Arguments ?? default); } private static void HandleArrayCreationExpression(SyntaxNodeAnalysisContext context) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1120CommentsMustContainText.cs b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1120CommentsMustContainText.cs index 77c13b4b1..6adbf8c34 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1120CommentsMustContainText.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1120CommentsMustContainText.cs @@ -82,10 +82,8 @@ private static void HandleMultiLineComment(SyntaxTreeAnalysisContext context, Sy private static void HandleSingleLineComment(SyntaxTreeAnalysisContext context, SyntaxTrivia singleLineComment) { - int index = 0; - // PERF: Explicitly cast to IReadOnlyList so we only box once. - IReadOnlyList list = TriviaHelper.GetContainingTriviaList(singleLineComment, out index); + IReadOnlyList list = TriviaHelper.GetContainingTriviaList(singleLineComment, out int index); var firstNonWhiteSpace = TriviaHelper.IndexOfFirstNonWhitespaceTrivia(list); // When we encounter a block of single line comments, we only want to raise this diagnostic diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1122UseStringEmptyForEmptyStrings.cs b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1122UseStringEmptyForEmptyStrings.cs index 1a13a2700..08172838f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1122UseStringEmptyForEmptyStrings.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1122UseStringEmptyForEmptyStrings.cs @@ -88,14 +88,12 @@ private static bool HasToBeConstant(LiteralExpressionSyntax literalExpression) if (outermostExpression.Parent is EqualsValueClauseSyntax equalsValueClause) { - if (equalsValueClause.Parent is ParameterSyntax parameterSyntax) + if (equalsValueClause.Parent is ParameterSyntax) { return true; } - VariableDeclaratorSyntax variableDeclaratorSyntax = equalsValueClause.Parent as VariableDeclaratorSyntax; - VariableDeclarationSyntax variableDeclarationSyntax = variableDeclaratorSyntax?.Parent as VariableDeclarationSyntax; - if (variableDeclaratorSyntax == null || variableDeclarationSyntax == null) + if (!(equalsValueClause.Parent is VariableDeclaratorSyntax variableDeclaratorSyntax) || !(variableDeclaratorSyntax?.Parent is VariableDeclarationSyntax variableDeclarationSyntax)) { return false; } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1130UseLambdaSyntax.cs b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1130UseLambdaSyntax.cs index 326b151d3..9fef6041b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1130UseLambdaSyntax.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1130UseLambdaSyntax.cs @@ -27,7 +27,6 @@ internal class SA1130UseLambdaSyntax : DiagnosticAnalyzer private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(ReadabilityResources.SA1130MessageFormat), ReadabilityResources.ResourceManager, typeof(ReadabilityResources)); private static readonly LocalizableString Description = new LocalizableResourceString(nameof(ReadabilityResources.SA1130Description), ReadabilityResources.ResourceManager, typeof(ReadabilityResources)); private static readonly string HelpLink = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1130.md"; - private static readonly ParameterListSyntax EmptyParameterList = SyntaxFactory.ParameterList(); private static readonly DiagnosticDescriptor Descriptor = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.ReadabilityRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink); @@ -128,9 +127,7 @@ private static void HandleAnonymousMethodExpression(SyntaxNodeAnalysisContext co private static bool HandleMethodInvocation(SemanticModel semanticModel, AnonymousMethodExpressionSyntax anonymousMethod, ArgumentSyntax argumentSyntax) { // invocation -> argument list -> argument -> anonymous method - var argumentListSyntax = argumentSyntax?.Parent as BaseArgumentListSyntax; - - if (argumentListSyntax != null) + if (argumentSyntax?.Parent is BaseArgumentListSyntax argumentListSyntax) { var originalInvocableExpression = argumentListSyntax.Parent; SymbolInfo originalSymbolInfo = semanticModel.GetSymbolInfo(originalInvocableExpression); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1142ReferToTupleElementsByName.cs b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1142ReferToTupleElementsByName.cs index 8605b3d03..f76a54cc9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1142ReferToTupleElementsByName.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1142ReferToTupleElementsByName.cs @@ -51,8 +51,7 @@ private static void HandleSimpleMemberAccessExpression(SyntaxNodeAnalysisContext var memberAccessExpression = (MemberAccessExpressionSyntax)context.Node; - var fieldSymbol = context.SemanticModel.GetSymbolInfo(memberAccessExpression).Symbol as IFieldSymbol; - if (fieldSymbol == null) + if (!(context.SemanticModel.GetSymbolInfo(memberAccessExpression).Symbol is IFieldSymbol fieldSymbol)) { return; } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/ObjectModel/DocumentationSettings.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/ObjectModel/DocumentationSettings.cs index 2815bf679..977f22938 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/ObjectModel/DocumentationSettings.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/ObjectModel/DocumentationSettings.cs @@ -293,41 +293,41 @@ public string GetCopyrightText(string fileName) private KeyValuePair BuildCopyrightText(string fileName) { bool canCache = true; - string pattern = Regex.Escape("{") + "(?[a-zA-Z0-9]+)" + Regex.Escape("}"); - MatchEvaluator evaluator = - match => - { - string key = match.Groups["Property"].Value; - switch (key) - { - case "companyName": - return this.CompanyName; - case "copyrightText": - return "[CircularReference]"; + string Evaluator(Match match) + { + string key = match.Groups["Property"].Value; + switch (key) + { + case "companyName": + return this.CompanyName; - default: - string value; - if (this.Variables.TryGetValue(key, out value)) - { - return value; - } + case "copyrightText": + return "[CircularReference]"; - if (key == "fileName") - { - // The 'fileName' built-in variable is only applied when the user did not include an - // explicit value for a custom 'fileName' variable. - canCache = false; - return fileName; - } + default: + string value; + if (this.Variables.TryGetValue(key, out value)) + { + return value; + } - break; + if (key == "fileName") + { + // The 'fileName' built-in variable is only applied when the user did not include an + // explicit value for a custom 'fileName' variable. + canCache = false; + return fileName; } - return "[InvalidReference]"; - }; + break; + } - string expanded = Regex.Replace(this.copyrightText, pattern, evaluator); + return "[InvalidReference]"; + } + + string pattern = Regex.Escape("{") + "(?[a-zA-Z0-9]+)" + Regex.Escape("}"); + string expanded = Regex.Replace(this.copyrightText, pattern, Evaluator); return new KeyValuePair(expanded, canCache); } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/ObjectModel/SpacingSettings.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/ObjectModel/SpacingSettings.cs index f177f48ed..d0bd811ab 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/ObjectModel/SpacingSettings.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/ObjectModel/SpacingSettings.cs @@ -21,6 +21,8 @@ protected internal SpacingSettings() protected internal SpacingSettings(JsonObject spacingSettingsObject) : this() { + // Currently unused + _ = spacingSettingsObject; } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs index 3ecf264aa..350087dd2 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs @@ -155,7 +155,7 @@ private static StyleCopSettings GetStyleCopSettings(string path, SourceText text throw new JsonParseException( $"Settings file at '{path}' was missing or empty.", JsonParseException.ErrorType.InvalidOrUnexpectedCharacter, - default(TextPosition)); + default); } var settingsObject = rootValue.AsJsonObject["settings"]; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1025CodeMustNotContainMultipleWhitespaceInARow.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1025CodeMustNotContainMultipleWhitespaceInARow.cs index 1e07cd0da..5df3ab43d 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1025CodeMustNotContainMultipleWhitespaceInARow.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1025CodeMustNotContainMultipleWhitespaceInARow.cs @@ -109,7 +109,7 @@ private static void HandleWhitespaceTrivia(SyntaxTreeAnalysisContext context, Sy return; } - var followingTrivia = index + 1 < list.Count ? list[index + 1] : default(SyntaxTrivia); + var followingTrivia = index + 1 < list.Count ? list[index + 1] : default; if (precedingToken.IsKind(SyntaxKind.CommaToken) || precedingToken.IsKind(SyntaxKind.SemicolonToken) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1028CodeMustNotContainTrailingWhitespace.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1028CodeMustNotContainTrailingWhitespace.cs index 5fd510839..8490a96b9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1028CodeMustNotContainTrailingWhitespace.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1028CodeMustNotContainTrailingWhitespace.cs @@ -68,7 +68,7 @@ private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context) var root = context.Tree.GetRoot(context.CancellationToken); var text = context.Tree.GetText(context.CancellationToken); - SyntaxTrivia previousTrivia = default(SyntaxTrivia); + SyntaxTrivia previousTrivia = default; foreach (var trivia in root.DescendantTrivia(descendIntoTrivia: true)) { switch (trivia.Kind()) @@ -131,7 +131,7 @@ private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context) case SyntaxKind.SingleLineDocumentationCommentTrivia: case SyntaxKind.MultiLineDocumentationCommentTrivia: - SyntaxToken previousToken = default(SyntaxToken); + SyntaxToken previousToken = default; foreach (var token in trivia.GetStructure().DescendantTokens(descendIntoTrivia: true)) { if (token.IsKind(SyntaxKind.XmlTextLiteralNewLineToken) diff --git a/StyleCop.Analyzers/StyleCopTester/Program.cs b/StyleCop.Analyzers/StyleCopTester/Program.cs index c38e5163c..ef5e6e21c 100644 --- a/StyleCop.Analyzers/StyleCopTester/Program.cs +++ b/StyleCop.Analyzers/StyleCopTester/Program.cs @@ -129,7 +129,7 @@ private static async Task MainAsync(string[] args, CancellationToken cancellatio bool force = args.Contains("/force"); - var diagnostics = await GetAnalyzerDiagnosticsAsync(solution, solutionPath, analyzers, force, cancellationToken).ConfigureAwait(true); + var diagnostics = await GetAnalyzerDiagnosticsAsync(solution, analyzers, force, cancellationToken).ConfigureAwait(true); var allDiagnostics = diagnostics.SelectMany(i => i.Value).ToImmutableArray(); Console.WriteLine($"Found {allDiagnostics.Length} diagnostics in {stopwatch.ElapsedMilliseconds}ms"); @@ -528,24 +528,7 @@ private static ImmutableDictionary> GetAl return providers.ToImmutableDictionary(); } - private static ImmutableDictionary> GetAllFixAllProviders(IEnumerable providers) - { - Dictionary> fixAllProviders = new Dictionary>(); - - foreach (var provider in providers) - { - var fixAllProvider = provider.GetFixAllProvider(); - var supportedDiagnosticIds = fixAllProvider.GetSupportedFixAllDiagnosticIds(provider); - foreach (var id in supportedDiagnosticIds) - { - fixAllProviders.AddToInnerSet(fixAllProvider, id); - } - } - - return fixAllProviders.ToImmutableDictionary(); - } - - private static async Task>> GetAnalyzerDiagnosticsAsync(Solution solution, string solutionPath, ImmutableArray analyzers, bool force, CancellationToken cancellationToken) + private static async Task>> GetAnalyzerDiagnosticsAsync(Solution solution, ImmutableArray analyzers, bool force, CancellationToken cancellationToken) { List>>> projectDiagnosticTasks = new List>>>();