Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
- Refactor
  • Loading branch information
maroontress-tomohisa committed May 11, 2024
1 parent 254e5a4 commit e98fcd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,30 @@ private static DiagnosticDescriptor NewRule()

private static Func<IMethodSymbol, bool> NewTargetMethodPredicate()
{
static string GetTypeNames() => EmbeddedResources.GetText(
"Refactoring.DiscardingReturnValue", "TypeNames.txt");

static string ToKey(IMethodSymbol method, INamedTypeSymbol type)
=> $"{method.ContainingNamespace.Name}.{type.Name}";

var methodNames = new HashSet<string>()
{
"System.IO.Stream.Read(byte[], int, int)",
"System.IO.BinaryReader.Read(byte[], int, int)",
};

static string GetTypeNames() => EmbeddedResources.GetText(
"Refactoring.DiscardingReturnValue", "TypeNames.txt");

var typeNames = GetTypeNames().Split(
[Platforms.NewLine()], StringSplitOptions.RemoveEmptyEntries)
.ToImmutableHashSet();
var typePredicates = new Dictionary<string, Func<IMethodSymbol, bool>>
{
["System.Type"] = m => m.Name is not "InvokeMember",
};
return m =>
{
if (methodNames.Contains(m.ToString()))
{
return true;
}
if (m.ContainingType.OriginalDefinition is not {} containingType)
{
return false;
}
if (typeNames.Contains(containingType.ToString()))
{
return true;
}
return typePredicates.TryGetValue(
$"{m.ContainingNamespace.Name}.{containingType.Name}",
out var predicate) && predicate(m);
};
return m => methodNames.Contains(m.ToString())
|| (m.ContainingType.OriginalDefinition is {} containingType
&& (typeNames.Contains(containingType.ToString())
|| (typePredicates.TryGetValue(
ToKey(m, containingType), out var predicate)
&& predicate(m))));
}

private static void AnalyzeModel(
Expand Down Expand Up @@ -149,7 +139,7 @@ static Func<IMethodSymbol, bool> NewContainsSet(
.Select(s => s.Expression)
.OfType<InvocationExpressionSyntax>()
.SelectMany(s => (model.GetOperation(s) is IInvocationOperation o
&& o.TargetMethod is {ReturnsVoid: false} target
&& o.TargetMethod is { ReturnsVoid: false } target
&& (IsMarkedAsDoNotIgnore(target)
|| TargetMethodPredicate(target)
|| containsSet(target))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ static bool IsLessThanOrLessThanEquals(SyntaxKind kind)
if (node is not ForStatementSyntax forNode
|| forNode.Declaration is not {} declaration
|| forNode.Condition is not {} condition
|| forNode.Initializers is not {Count: 0} allInitializers
|| forNode.Incrementors is not {Count: 1} allIncrementors)
|| forNode.Initializers is not { Count: 0 } allInitializers
|| forNode.Incrementors is not { Count: 1 } allIncrementors)
{
return null;
}
Expand Down

0 comments on commit e98fcd7

Please sign in to comment.