Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump code style package to 3.9.0 #4919

Merged
merged 12 commits into from
Apr 14, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ private static void AnalyzeSymbol(INamedTypeSymbol symbol, Action<Diagnostic> ad

private static bool IsDllImport(ISymbol symbol)
{
#pragma warning disable IDE0078 // Use pattern matching - https://github.com/dotnet/roslyn/issues/51691
return symbol.Kind == SymbolKind.Method && ((IMethodSymbol)symbol).GetDllImportData() != null;
#pragma warning restore IDE0078 // Use pattern matching
}

private static bool IsTypeNamedCorrectly(string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public override void Initialize(AnalysisContext context)
}

static bool IsDelegateTypeWithInvokeMethod(INamedTypeSymbol namedType) =>
#pragma warning disable IDE0078 // Use pattern matching - https://github.com/dotnet/roslyn/issues/51691
namedType.TypeKind == TypeKind.Delegate && namedType.DelegateInvokeMethod != null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ Is this not the same?

Suggested change
namedType.TypeKind == TypeKind.Delegate && namedType.DelegateInvokeMethod != null;
namedType is { TypeKind: TypeKind.Delegate, DelegateInvokeMethod: not null };

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharwell There are actually more IDE0078 violations than the ones I suppressed. Some of them are actionable like you suggested, and others doesn't seem to be actionable. I'm thinking of setting the rule to silent for now until the analyzer and codefix bugs are fixed to avoid the many suppressions and manual fixes. Would you be okay with that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly

#pragma warning restore IDE0078 // Use pattern matching

context.RegisterSymbolAction(symbolContext =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private static bool IsOnObsoleteMemberChain(ISymbol symbol, WellKnownTypeProvide
while (symbol != null)
{
allAttributes.AddRange(symbol.GetAttributes());
symbol = symbol is IMethodSymbol method && method.AssociatedSymbol != null
symbol = symbol is IMethodSymbol { AssociatedSymbol: not null } method
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a manual change. The codefix produces invalid code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has the bug been filed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is dotnet/roslyn#51691.

? method.AssociatedSymbol :
symbol.ContainingSymbol;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ internal static async Task<NamedTypeMetricData> ComputeAsync(INamedTypeSymbol na
// Compat: Filter out nested types as they are children of most closest containing namespace.
var members = namedType.GetMembers().Where(m => m.Kind != SymbolKind.NamedType);

#pragma warning disable IDE0078 // Use pattern matching - https://github.com/dotnet/roslyn/issues/51691
#if LEGACY_CODE_METRICS_MODE
// Legacy mode skips metrics for field/property/event symbols, and explicitly includes accessors as methods.
members = members.Where(m => m.Kind is not SymbolKind.Field and not SymbolKind.Property and not SymbolKind.Event);
#else
// Filter out accessors as they are children of their associated symbols, for which we generate a separate node.
members = members.Where(m => m.Kind != SymbolKind.Method || ((IMethodSymbol)m).AssociatedSymbol == null);
#endif
#pragma warning restore IDE0078 // Use pattern matching

ImmutableArray<CodeAnalysisMetricData> children = await ComputeAsync(members, context).ConfigureAwait(false);

Expand Down
2 changes: 2 additions & 0 deletions src/Utilities/Compiler/Extensions/IOperationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ public static ImmutableArray<IOperation> GetTopmostExplicitDescendants(this IOpe
/// </summary>
public static bool IsOperationNoneRoot(this IOperation operation)
{
#pragma warning disable IDE0078 // Use pattern matching - https://github.com/dotnet/roslyn/issues/51691
return operation.Kind == OperationKind.None && operation.Parent == null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭

Suggested change
return operation.Kind == OperationKind.None && operation.Parent == null;
return operation is { Kind: OperationKind.None, Parent: null };

#pragma warning restore IDE0078 // Use pattern matching
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ internal static bool IsSupportedType(ITypeSymbol type, [NotNullWhen(returnValue:
valueTypeSymbol = type;
return true;
}
else if (type is INamedTypeSymbol namedTypeSymbol
&& namedTypeSymbol.EnumUnderlyingType != null)
else if (type is INamedTypeSymbol { EnumUnderlyingType: not null } namedTypeSymbol)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a manual change. The codefix produces invalid code.

{
valueTypeSymbol = namedTypeSymbol.EnumUnderlyingType;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,9 @@ private void OnStartExitBlockAnalysis(BasicBlock exitBlock)
AnalysisEntity analysisEntity = kvp.Value;

// Escape parameter values on exit, except for ref/out parameters in interprocedural analysis.
#pragma warning disable IDE0078 // Use pattern matching - https://github.com/dotnet/roslyn/issues/51691
if (parameter.RefKind == RefKind.None || DataFlowAnalysisContext.InterproceduralAnalysisData == null)
#pragma warning restore IDE0078 // Use pattern matching
{
EscapeValueForParameterOnExit(parameter, analysisEntity);
}
Expand Down