提交 ee660b5e 编写于 作者: M Manish Vasani

[Dogfooding[ Enforce IDE0011 (Add braces) as a build warning for some IDE projects

My prior attempt to enable this as a build warning in https://github.com/dotnet/roslyn/pull/44164 did not work due to #44201. This PR actually adds the build enforcement and fixes the violations.
上级 5bd1f86c
......@@ -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
......
......@@ -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())
{
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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];
......
......@@ -93,8 +93,10 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
// issue there.
if (startTrivia.RawKind == _syntaxKinds.ConflictMarkerTrivia ||
middleTrivia.RawKind == _syntaxKinds.ConflictMarkerTrivia)
{
return false;
}
}
return true;
}
......
......@@ -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++;
......
......@@ -237,8 +237,10 @@ internal async Task<Solution> SimplifyAsync(Solution solution, IEnumerable<Docum
var builder = ImmutableDictionary.CreateBuilder<DocumentId, ImmutableArray<ComplexifiedSpan>>();
foreach (var (docId, spans) in _documentToComplexifiedSpansMap)
{
builder.Add(docId, spans.SelectAsArray(
s => new ComplexifiedSpan(s.OriginalSpan, s.NewSpan, s.ModifiedSubSpans.ToImmutableArray())));
}
return builder.ToImmutable();
}
......
......@@ -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))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册