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

Fix HarmonyMethodRefParametersAnalyzer incorrectly marking member accesses as warning #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<PropertyGroup>
<PackageId>BepInEx.Analyzers</PackageId>
<PackageVersion>1.0.8</PackageVersion>
<PackageVersion>1.0.9</PackageVersion>
<Authors>BepInEx</Authors>
<PackageProjectUrl>https://github.com/BepInEx/BepInEx.Analyzers</PackageProjectUrl>
<PackageIconUrl>https://avatars2.githubusercontent.com/u/39589027</PackageIconUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,9 @@ private void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context)
if (method.ParameterList?.Parameters.Count <= 0)
return;

var memberAccesses = context.Node.DescendantNodes().OfType<MemberAccessExpressionSyntax>();
var varNames = memberAccesses.Select(e => e.Expression.ToString()).ToList();
CheckExpressionSyntaxes(context, method, varNames, memberAccesses.Cast<ExpressionSyntax>().ToList());

var assignments = context.Node.DescendantNodes().OfType<AssignmentExpressionSyntax>();
varNames = assignments.Select(e => e.Left.ToString()).ToList();
var varNames = assignments.Select(e => e.Left.ToString()).ToList();
CheckExpressionSyntaxes(context, method, varNames, assignments.Cast<ExpressionSyntax>().ToList());

var accessesByIndex = context.Node.DescendantNodes().OfType<ElementAccessExpressionSyntax>();
varNames = accessesByIndex.Select(e => e.Expression.ToString()).ToList();
CheckExpressionSyntaxes(context, method, varNames, accessesByIndex.Cast<ExpressionSyntax>().ToList());
}

private static void CheckExpressionSyntaxes(SyntaxNodeAnalysisContext context, MethodDeclarationSyntax method,
Expand All @@ -60,15 +52,7 @@ private static void CheckExpressionSyntaxes(SyntaxNodeAnalysisContext context, M
{
foreach (var parameter in method.ParameterList.Parameters)
{
// If parameter is a reference type and is not a literal assignment no warning needed
var parameterSymbol = context.SemanticModel.GetDeclaredSymbol(parameter, context.CancellationToken);
if (parameterSymbol.Type.IsReferenceType)
{
if (!(expressionSyntaxes[i] is AssignmentExpressionSyntax assignment))
{
continue;
}
}

var parameterName = parameterSymbol.Name;
if (parameterSymbol.RefKind == RefKind.None && parameterName == varNames[i])
Expand Down