diff --git a/.editorconfig b/.editorconfig index 699fb17642c9f2f4373524f81156f541ce758293..c21dd878f51cc5cd7dd492dd97a1f26ae2a6aed4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -231,6 +231,8 @@ dotnet_diagnostic.IDE0005.severity = warning # IDE0011: Add braces csharp_prefer_braces = when_multiline:warning +# NOTE: We need the below severity entry for Add Braces due to https://github.com/dotnet/roslyn/issues/44201 +dotnet_diagnostic.IDE0011.severity = warning # IDE0035: Remove unreachable code dotnet_diagnostic.IDE0035.severity = warning diff --git a/src/Compilers/CSharp/CSharpAnalyzerDriver/CSharpDeclarationComputer.cs b/src/Compilers/CSharp/CSharpAnalyzerDriver/CSharpDeclarationComputer.cs index b930a860512b701bffae79d5a523f5ce65499aa9..369a958180fc9adcd484f1017cc0509442af5f5a 100644 --- a/src/Compilers/CSharp/CSharpAnalyzerDriver/CSharpDeclarationComputer.cs +++ b/src/Compilers/CSharp/CSharpAnalyzerDriver/CSharpDeclarationComputer.cs @@ -72,7 +72,11 @@ private static bool InvalidLevel(int? level) case SyntaxKind.NamespaceDeclaration: { var ns = (NamespaceDeclarationSyntax)node; - foreach (var decl in ns.Members) ComputeDeclarations(model, decl, shouldSkip, getSymbol, builder, newLevel, cancellationToken); + foreach (var decl in ns.Members) + { + ComputeDeclarations(model, decl, shouldSkip, getSymbol, builder, newLevel, cancellationToken); + } + var declInfo = GetDeclarationInfo(model, node, getSymbol, cancellationToken); builder.Add(declInfo); @@ -94,7 +98,11 @@ private static bool InvalidLevel(int? level) case SyntaxKind.InterfaceDeclaration: { var t = (TypeDeclarationSyntax)node; - foreach (var decl in t.Members) ComputeDeclarations(model, decl, shouldSkip, getSymbol, builder, newLevel, cancellationToken); + foreach (var decl in t.Members) + { + ComputeDeclarations(model, decl, shouldSkip, getSymbol, builder, newLevel, cancellationToken); + } + var attributes = GetAttributes(t.AttributeLists).Concat(GetTypeParameterListAttributes(t.TypeParameterList)); builder.Add(GetDeclarationInfo(model, node, getSymbol, attributes, cancellationToken)); return; @@ -103,7 +111,11 @@ private static bool InvalidLevel(int? level) case SyntaxKind.EnumDeclaration: { var t = (EnumDeclarationSyntax)node; - foreach (var decl in t.Members) ComputeDeclarations(model, decl, shouldSkip, getSymbol, builder, newLevel, cancellationToken); + foreach (var decl in t.Members) + { + ComputeDeclarations(model, decl, shouldSkip, getSymbol, builder, newLevel, cancellationToken); + } + var attributes = GetAttributes(t.AttributeLists); builder.Add(GetDeclarationInfo(model, node, getSymbol, attributes, cancellationToken)); return; @@ -133,7 +145,10 @@ private static bool InvalidLevel(int? level) var t = (EventDeclarationSyntax)node; if (t.AccessorList != null) { - foreach (var decl in t.AccessorList.Accessors) ComputeDeclarations(model, decl, shouldSkip, getSymbol, builder, newLevel, cancellationToken); + foreach (var decl in t.AccessorList.Accessors) + { + ComputeDeclarations(model, decl, shouldSkip, getSymbol, builder, newLevel, cancellationToken); + } } var attributes = GetAttributes(t.AttributeLists); builder.Add(GetDeclarationInfo(model, node, getSymbol, attributes, cancellationToken)); @@ -170,7 +185,10 @@ private static bool InvalidLevel(int? level) var t = (PropertyDeclarationSyntax)node; if (t.AccessorList != null) { - foreach (var decl in t.AccessorList.Accessors) ComputeDeclarations(model, decl, shouldSkip, getSymbol, builder, newLevel, cancellationToken); + foreach (var decl in t.AccessorList.Accessors) + { + ComputeDeclarations(model, decl, shouldSkip, getSymbol, builder, newLevel, cancellationToken); + } } if (t.ExpressionBody != null) @@ -259,7 +277,10 @@ private static bool InvalidLevel(int? level) case SyntaxKind.CompilationUnit: { var t = (CompilationUnitSyntax)node; - foreach (var decl in t.Members) ComputeDeclarations(model, decl, shouldSkip, getSymbol, builder, newLevel, cancellationToken); + foreach (var decl in t.Members) + { + ComputeDeclarations(model, decl, shouldSkip, getSymbol, builder, newLevel, cancellationToken); + } if (t.AttributeLists.Any()) { diff --git a/src/Features/CSharp/Portable/ConvertLinq/CSharpConvertLinqQueryToForEachProvider.cs b/src/Features/CSharp/Portable/ConvertLinq/CSharpConvertLinqQueryToForEachProvider.cs index 70843bcef93367377433becd0af27cdf32576b0c..c2c5c7e55dfd3c1ef1c15729ac60ef2d0b16b382 100644 --- a/src/Features/CSharp/Portable/ConvertLinq/CSharpConvertLinqQueryToForEachProvider.cs +++ b/src/Features/CSharp/Portable/ConvertLinq/CSharpConvertLinqQueryToForEachProvider.cs @@ -98,8 +98,10 @@ public bool TryConvert(out DocumentUpdateInfo documentUpdateInfo) { if (!documentUpdateInfo.Source.IsParentKind(SyntaxKind.Block) && documentUpdateInfo.Destinations.Length > 1) - + { documentUpdateInfo = new DocumentUpdateInfo(documentUpdateInfo.Source, SyntaxFactory.Block(documentUpdateInfo.Destinations)); + } + return true; } diff --git a/src/Features/CSharp/Portable/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs b/src/Features/CSharp/Portable/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs index 374a18fb62e53c375e5af26538a8b5653d98f8a8..a26952fcbfaf0c94e813a540a2a574c760b64ba0 100644 --- a/src/Features/CSharp/Portable/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs @@ -155,7 +155,9 @@ where m.IsAccessibleWithin(enclosingType) { if (!CanFix(semanticModel, diagnostic, cancellationToken, out var nameNode, out var matchingMember, out _)) + { continue; + } var newNameNode = matchingMember.Name.ToIdentifierName(); var newExpr = (ExpressionSyntax)newNameNode; diff --git a/src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceVariableService_IntroduceLocal.cs b/src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceVariableService_IntroduceLocal.cs index 5d24c1e094fdfef03b025396c00e3a9819c8418b..6ce0acb981c169b366f26566efa888a87d670598 100644 --- a/src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceVariableService_IntroduceLocal.cs +++ b/src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceVariableService_IntroduceLocal.cs @@ -419,8 +419,10 @@ private int GetFirstStatementAffectedIndex(SyntaxNode innermostCommonBlock, ISet var nextStatementLeading = nextStatement.GetLeadingTrivia(); var precedingEndOfLine = nextStatementLeading.LastOrDefault(t => t.Kind() == SyntaxKind.EndOfLineTrivia); if (precedingEndOfLine == default) + { return oldStatements.ReplaceRange( nextStatement, new[] { newStatement, nextStatement }); + } var endOfLineIndex = nextStatementLeading.IndexOf(precedingEndOfLine) + 1; diff --git a/src/Features/CSharp/Portable/ReverseForStatement/CSharpReverseForStatementCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/ReverseForStatement/CSharpReverseForStatementCodeRefactoringProvider.cs index 20390a88919c5424470b38783c7dc1d6cb18987d..dd06b42fb65b9a8f9dccb79bdd2174fc2f2fb19d 100644 --- a/src/Features/CSharp/Portable/ReverseForStatement/CSharpReverseForStatementCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/ReverseForStatement/CSharpReverseForStatementCodeRefactoringProvider.cs @@ -53,7 +53,9 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte if (declaration == null || declaration.Variables.Count != 1 || forStatement.Incrementors.Count != 1) + { return; + } var variable = declaration.Variables[0]; var after = forStatement.Incrementors[0]; diff --git a/src/Features/Core/Portable/ConflictMarkerResolution/AbstractConflictMarkerCodeFixProvider.cs b/src/Features/Core/Portable/ConflictMarkerResolution/AbstractConflictMarkerCodeFixProvider.cs index eebe4a0a83f1f937873dc962fefd975aff188df8..920e1f741ca6ded9ed879eb5f11a7bbd1ce6664e 100644 --- a/src/Features/Core/Portable/ConflictMarkerResolution/AbstractConflictMarkerCodeFixProvider.cs +++ b/src/Features/Core/Portable/ConflictMarkerResolution/AbstractConflictMarkerCodeFixProvider.cs @@ -93,7 +93,9 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) // issue there. if (startTrivia.RawKind == _syntaxKinds.ConflictMarkerTrivia || middleTrivia.RawKind == _syntaxKinds.ConflictMarkerTrivia) + { return false; + } } return true; diff --git a/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/RegexCharClass.cs b/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/RegexCharClass.cs index 9b967b47b48e811ec27cb42f04e9685d7440eb72..68532e2e93f6218bba2e6c4392f1023d3f32ae00 100644 --- a/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/RegexCharClass.cs +++ b/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/RegexCharClass.cs @@ -269,7 +269,9 @@ private static bool CharInClassInternal(char ch, string set, int start, int mySe // reverse this check. Debug.Assert((SETSTART & 0x1) == 1, "If SETSTART is not odd, the calculation below this will be reversed"); if ((min & 0x1) == (start & 0x1)) + { return true; + } else { if (myCategoryLength == 0) @@ -302,7 +304,9 @@ private static bool CharInCategory(char ch, string set, int start, int mySetLeng if (curcat == SpaceConst) { if (char.IsWhiteSpace(ch)) + { return true; + } else { i++; @@ -320,7 +324,9 @@ private static bool CharInCategory(char ch, string set, int start, int mySetLeng if (curcat == NotSpaceConst) { if (!char.IsWhiteSpace(ch)) + { return true; + } else { i++; diff --git a/src/Workspaces/Core/Portable/Rename/ConflictEngine/RenamedSpansTracker.cs b/src/Workspaces/Core/Portable/Rename/ConflictEngine/RenamedSpansTracker.cs index 5ab06e6c9a00f3f7411c5038f770f1590740f10f..77fb7dc4592cd9f1de8efb33167d30e1ef3b6696 100644 --- a/src/Workspaces/Core/Portable/Rename/ConflictEngine/RenamedSpansTracker.cs +++ b/src/Workspaces/Core/Portable/Rename/ConflictEngine/RenamedSpansTracker.cs @@ -237,8 +237,10 @@ internal async Task SimplifyAsync(Solution solution, IEnumerable>(); foreach (var (docId, spans) in _documentToComplexifiedSpansMap) + { builder.Add(docId, spans.SelectAsArray( s => new ComplexifiedSpan(s.OriginalSpan, s.NewSpan, s.ModifiedSubSpans.ToImmutableArray()))); + } return builder.ToImmutable(); } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SelectedMembers/AbstractSelectedMembers.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SelectedMembers/AbstractSelectedMembers.cs index ccd3678475cfceb61b08b104a26ea62034411308..c9a91e86f6ca25e05a085f60c5e8bce08c7224f3 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SelectedMembers/AbstractSelectedMembers.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SelectedMembers/AbstractSelectedMembers.cs @@ -102,7 +102,9 @@ void AddSelectedFieldOrPropertyDeclarations(TMemberDeclarationSyntax member) { if (!(member is TFieldDeclarationSyntax) && !(member is TPropertyDeclarationSyntax)) + { return; + } // first, check if entire member is selected. If so, we definitely include this member. if (textSpan.Contains(member.Span))