Skip to content

Commit

Permalink
Merge branch 'main' into resx-analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Dec 15, 2022
2 parents 237ed18 + ea8aa10 commit 8131b24
Show file tree
Hide file tree
Showing 161 changed files with 403 additions and 808 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,21 @@ dotnet_diagnostic.IDE0130.severity = silent
# IDE0150: Null check can be clarified
dotnet_diagnostic.IDE0150.severity = silent

# IDE2000: Allow multiple blank lines
dotnet_style_allow_multiple_blank_lines_experimental = false

# IDE2001: Embedded statements must be on their own line
csharp_style_allow_embedded_statements_on_same_line_experimental = false

# IDE2002: Consecutive braces must not have blank line between them
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false

# IDE2003: Blank line required between block and subsequent statement
dotnet_style_allow_statement_immediately_after_block_experimental = false

# IDE2004: Blank line not allowed after constructor initializer colon
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false

### Configuration for FxCop analyzers executed on this repo ###
[*.{cs,vb}]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private static void HandleBinaryOperator(in OperationAnalysisContext context, IN
{
context.ReportDiagnostic(invocationOperation.CreateDiagnostic(GetHashCodeRule));
}

break;

case s_symbolEqualsName:
Expand All @@ -176,6 +177,7 @@ private static void HandleBinaryOperator(in OperationAnalysisContext context, IN
context.ReportDiagnostic(invocationOperation.Syntax.GetLocation().CreateDiagnostic(EqualityRule));
}
}

break;

case s_HashCodeCombineName:
Expand All @@ -187,6 +189,7 @@ private static void HandleBinaryOperator(in OperationAnalysisContext context, IN
{
context.ReportDiagnostic(invocationOperation.CreateDiagnostic(GetHashCodeRule));
}

break;

default:
Expand All @@ -198,6 +201,7 @@ private static void HandleBinaryOperator(in OperationAnalysisContext context, IN
{
context.ReportDiagnostic(invocationOperation.CreateDiagnostic(CollectionRule));
}

break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
cancellationToken => UpdateEntryInUnshippedFileAsync(context.Document.Project, ruleId, entryToUpdate, cancellationToken),
equivalenceKey: CodeAnalysisDiagnosticsResources.UpdateEntryForDiagnosticIdInAnalyzerReleaseCodeFixTitle);
}

break;

case DiagnosticIds.EnableAnalyzerReleaseTrackingRuleId:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Analyzers.MetaAnalyzers.CodeFixes
If invocation Is Nothing Then
Return binaryExpression
End If

Dim newInvocation = invocation _
.WithExpression(ConvertKindNameToIsKind(invocation.Expression)) _
.AddArgumentListArguments(SyntaxFactory.SimpleArgument(binaryExpression.Right.WithoutTrailingTrivia())) _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private void OnCompilationStart(CompilationStartAnalysisContext compilationConte
VerifySymbol(context.ReportDiagnostic, conversion.OperatorMethod, context.Operation.Syntax);
VerifyType(context.ReportDiagnostic, conversion.OperatorMethod.ContainingType, context.Operation.Syntax);
}
break;
case IUnaryOperation unary:
Expand All @@ -109,6 +110,7 @@ private void OnCompilationStart(CompilationStartAnalysisContext compilationConte
VerifySymbol(context.ReportDiagnostic, unary.OperatorMethod, context.Operation.Syntax);
VerifyType(context.ReportDiagnostic, unary.OperatorMethod.ContainingType, context.Operation.Syntax);
}
break;
case IBinaryOperation binary:
Expand All @@ -117,6 +119,7 @@ private void OnCompilationStart(CompilationStartAnalysisContext compilationConte
VerifySymbol(context.ReportDiagnostic, binary.OperatorMethod, context.Operation.Syntax);
VerifyType(context.ReportDiagnostic, binary.OperatorMethod.ContainingType, context.Operation.Syntax);
}
break;
case IIncrementOrDecrementOperation incrementOrDecrement:
Expand All @@ -125,6 +128,7 @@ private void OnCompilationStart(CompilationStartAnalysisContext compilationConte
VerifySymbol(context.ReportDiagnostic, incrementOrDecrement.OperatorMethod, context.Operation.Syntax);
VerifyType(context.ReportDiagnostic, incrementOrDecrement.OperatorMethod.ContainingType, context.Operation.Syntax);
}
break;
case ITypeOfOperation typeOfOperation:
VerifyType(context.ReportDiagnostic, typeOfOperation.TypeOperand, context.Operation.Syntax);
Expand Down Expand Up @@ -220,6 +224,7 @@ bool VerifyTypeArguments(Action<Diagnostic> reportDiagnostic, ITypeSymbol? type,
return false;
}
}

break;

case IArrayTypeSymbol arrayTypeSymbol:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public bool Execute(GeneratorExecutionContext context)
RenderFormatMethod(memberIndent, language, strings, resourceString);
}
}

break;

case Lang.VisualBasic:
Expand All @@ -324,6 +325,7 @@ public bool Execute(GeneratorExecutionContext context)
{
throw new NotImplementedException();
}

break;

default:
Expand Down Expand Up @@ -378,6 +380,7 @@ public bool Execute(GeneratorExecutionContext context)
{memberIndent}}}
";
}

break;

case Lang.VisualBasic:
Expand All @@ -390,6 +393,7 @@ public bool Execute(GeneratorExecutionContext context)
{
throw new NotImplementedException();
}

break;

default:
Expand Down Expand Up @@ -450,6 +454,7 @@ public bool Execute(GeneratorExecutionContext context)
{resourceTypeDefinition}
}}";
}

break;

case Lang.VisualBasic:
Expand All @@ -461,6 +466,7 @@ public bool Execute(GeneratorExecutionContext context)
{resourceTypeDefinition}
End Namespace";
}

break;

default:
Expand Down Expand Up @@ -603,6 +609,7 @@ private static string CreateStringLiteral(string original, Lang lang)
{
stringLiteral.Append('@');
}

stringLiteral.Append('\"');
for (var i = 0; i < original.Length; i++)
{
Expand All @@ -611,8 +618,10 @@ private static string CreateStringLiteral(string original, Lang lang)
{
stringLiteral.Append('"');
}

stringLiteral.Append(original[i]);
}

stringLiteral.Append('\"');

return stringLiteral.ToString();
Expand Down Expand Up @@ -644,6 +653,7 @@ private static void RenderFormatMethod(string indent, Lang language, StringBuild
{
strings.AppendLine($@"{indent} => string.Format(Culture, GetResourceString(""{resourceString.Name}"") ?? """", {resourceString.GetArguments()});");
}

strings.AppendLine();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.

using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeQuality.Analyzers.QualityGuidelines.AvoidMultipleEnumerations;
using Microsoft.CodeQuality.Analyzers.QualityGuidelines.AvoidMultipleEnumerations.FlowAnalysis;

namespace Microsoft.CodeAnalysis.CSharp.NetAnalyzers.Microsoft.CodeQuality.Analyzers.QualityGuidelines
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal sealed partial class CSharpAvoidMultipleEnumerationsAnalyzer : AvoidMultipleEnumerations
{
protected override GlobalFlowStateDictionaryFlowOperationVisitor CreateOperationVisitor(
GlobalFlowStateDictionaryAnalysisContext context,
WellKnownSymbolsInfo wellKnownSymbolsInfo)
=> new CSharpInvocationCountValueSetFlowStateDictionaryFlowOperationVisitor(
context,
wellKnownSymbolsInfo);
protected override bool IsExpressionOfForEachStatement(SyntaxNode node)
=> node.Parent is ForEachStatementSyntax forEachStatementSyntax && forEachStatementSyntax.Expression.Equals(node);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fi
// We can't code fix if unsafe code isn't allowed.
return await document.GetSyntaxRootAsync(fixAllContext.CancellationToken);
}

var editor = await DocumentEditor.CreateAsync(document, fixAllContext.CancellationToken).ConfigureAwait(false);
SyntaxNode root = await document.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false);

Expand All @@ -47,12 +48,14 @@ protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fi
{
identifierGenerator = scopeMap[block] = new IdentifierGenerator(editor.SemanticModel, block);
}

if (TryRewriteMethodCall(node, editor, identifierGenerator, addRenameAnnotation: false, fixAllContext.CancellationToken))
{
AddUnsafeModifierToEnclosingMethod(editor, node);
}
}
}

return editor.GetChangedRoot();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public IdentifierGenerator(SemanticModel model, IBlockOperation block)
{
identifier = NextIdentifier();
}

if (identifier is not null)
{
// The last identifier was not in use, so go back one to use it the next call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
// We can't code fix if unsafe code isn't allowed.
return;
}

SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

SyntaxNode enclosingNode = root.FindNode(context.Span);
Expand Down Expand Up @@ -64,6 +65,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
return i;
}
}

return 0;
}

Expand Down Expand Up @@ -102,6 +104,7 @@ private static bool TryRewriteMethodCall(SyntaxNode node, DocumentEditor editor,
return true;
}
}

if (operation.TargetMethod.Name == "StructureToPtr" && operation.Arguments[0].Value.Type.IsUnmanagedType)
{
editor.ReplaceNode(syntax,
Expand All @@ -112,6 +115,7 @@ private static bool TryRewriteMethodCall(SyntaxNode node, DocumentEditor editor,
operation.Arguments[0].Value.Syntax));
return true;
}

if (operation.TargetMethod.Name == "PtrToStructure")
{
ITypeSymbol type;
Expand Down Expand Up @@ -178,6 +182,7 @@ private static bool TryRewriteMethodCall(SyntaxNode node, DocumentEditor editor,
{
return false;
}

editor.ReplaceNode(syntax, replacementNode);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public sealed class CSharpDynamicInterfaceCastableImplementationFixer : DynamicI
{
return null;
}

var methodDeclaration = generator.MethodDeclaration(method);
methodDeclaration = generator.WithModifiers(methodDeclaration, generator.GetModifiers(methodDeclaration).WithIsAbstract(false));
return generator.WithStatements(methodDeclaration, defaultMethodBodyStatements);
Expand All @@ -90,6 +91,7 @@ SyntaxNode GeneratePropertyImplementation(IPropertySymbol property)
{
propertyDeclaration = generator.WithGetAccessorStatements(propertyDeclaration, defaultMethodBodyStatements);
}

if (property.SetMethod is not null
&& model.Compilation.IsSymbolAccessibleWithin(property.SetMethod, type))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private sealed class CSharpDiagnosticHelper : DiagnosticHelper
{
return null;
}

var targetArg = attributeSyntax.ArgumentList.Arguments.FirstOrDefault(arg => arg.NameEquals.Name.IsEquivalentTo(targetNameSyntax, true));
return targetArg?.GetLocation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected override SyntaxNode GetHashDataSyntaxNode(PreferHashDataOverComputeHas
{
arg = arg.WithNameColon(arg.NameColon.WithName(SyntaxFactory.IdentifierName("source")));
}

var args = SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(arg));
return SyntaxFactory.InvocationExpression(hashData, args);
}
Expand All @@ -69,6 +70,7 @@ protected override SyntaxNode GetHashDataSyntaxNode(PreferHashDataOverComputeHas
{
list[secondArgIndex] = secondArg.WithNameColon(SyntaxFactory.NameColon(SyntaxFactory.IdentifierName("start")));
}

var thirdArg = list[thirdArgIndex];
if (thirdArg.NameColon is not null)
{
Expand All @@ -90,6 +92,7 @@ protected override SyntaxNode GetHashDataSyntaxNode(PreferHashDataOverComputeHas
{
arg = arg.WithNameColon(SyntaxFactory.NameColon(SyntaxFactory.IdentifierName("source")));
}

var args = SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(arg));
return SyntaxFactory.InvocationExpression(hashData, args);
}
Expand Down Expand Up @@ -135,6 +138,7 @@ protected override SyntaxNode FixHashCreateNode(SyntaxNode root, SyntaxNode crea
break;
}
}

return root;
}

Expand Down Expand Up @@ -165,6 +169,7 @@ private SyntaxNode MoveStatementsOutOfUsingStatementWithFormatting(SyntaxNode ro
newTrivia = AddRangeIfInteresting(newTrivia, usingStatement.GetTrailingTrivia());
statement = statement.WithTrailingTrivia(newTrivia);
}
return statement;
});

Expand Down Expand Up @@ -197,7 +202,6 @@ protected override bool IsInterestingTrivia(SyntaxTriviaList triviaList)
{
ns = qualifiedNamespaceSyntax.ToFullString();
}

}
else if (invocationNode.Expression is MemberAccessExpressionSyntax { Expression: InvocationExpressionSyntax { Expression: MemberAccessExpressionSyntax { Expression: MemberAccessExpressionSyntax originalType } } })
{
Expand All @@ -214,7 +218,6 @@ protected override bool IsInterestingTrivia(SyntaxTriviaList triviaList)
ns = qualifiedNamespaceSyntax.ToFullString();
}


return ns;
}
}
Expand Down

0 comments on commit 8131b24

Please sign in to comment.