From a22ff84856a47a4757c769ddc51e542db31743e9 Mon Sep 17 00:00:00 2001 From: xiaoxiao921 Date: Sat, 29 Jan 2022 00:15:33 +0100 Subject: [PATCH 1/2] only Assignment expressions matter for RefParameters Analyzer --- .../HarmonyMethodRefParametersAnalyzer.cs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/BepInEx.Analyzers/BepInEx.Analyzers/HarmonyMethodRefParametersAnalyzer.cs b/BepInEx.Analyzers/BepInEx.Analyzers/HarmonyMethodRefParametersAnalyzer.cs index c562ebd..f872f10 100644 --- a/BepInEx.Analyzers/BepInEx.Analyzers/HarmonyMethodRefParametersAnalyzer.cs +++ b/BepInEx.Analyzers/BepInEx.Analyzers/HarmonyMethodRefParametersAnalyzer.cs @@ -40,17 +40,9 @@ private void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context) if (method.ParameterList?.Parameters.Count <= 0) return; - var memberAccesses = context.Node.DescendantNodes().OfType(); - var varNames = memberAccesses.Select(e => e.Expression.ToString()).ToList(); - CheckExpressionSyntaxes(context, method, varNames, memberAccesses.Cast().ToList()); - var assignments = context.Node.DescendantNodes().OfType(); - varNames = assignments.Select(e => e.Left.ToString()).ToList(); + var varNames = assignments.Select(e => e.Left.ToString()).ToList(); CheckExpressionSyntaxes(context, method, varNames, assignments.Cast().ToList()); - - var accessesByIndex = context.Node.DescendantNodes().OfType(); - varNames = accessesByIndex.Select(e => e.Expression.ToString()).ToList(); - CheckExpressionSyntaxes(context, method, varNames, accessesByIndex.Cast().ToList()); } private static void CheckExpressionSyntaxes(SyntaxNodeAnalysisContext context, MethodDeclarationSyntax method, @@ -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]) From 2a7129e3c7d33d14fdd65c7063098c3daa59bb2a Mon Sep 17 00:00:00 2001 From: xiaoxiao921 Date: Sat, 29 Jan 2022 00:16:08 +0100 Subject: [PATCH 2/2] Bump version --- .../BepInEx.Analyzers.Package/BepInEx.Analyzers.Package.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BepInEx.Analyzers/BepInEx.Analyzers.Package/BepInEx.Analyzers.Package.csproj b/BepInEx.Analyzers/BepInEx.Analyzers.Package/BepInEx.Analyzers.Package.csproj index 353d76c..8a10783 100644 --- a/BepInEx.Analyzers/BepInEx.Analyzers.Package/BepInEx.Analyzers.Package.csproj +++ b/BepInEx.Analyzers/BepInEx.Analyzers.Package/BepInEx.Analyzers.Package.csproj @@ -11,7 +11,7 @@ BepInEx.Analyzers - 1.0.8 + 1.0.9 BepInEx https://github.com/BepInEx/BepInEx.Analyzers https://avatars2.githubusercontent.com/u/39589027