From e9c817557b3981f8756c5c711fe53ea4d807ed97 Mon Sep 17 00:00:00 2001 From: James Truher Date: Thu, 18 Oct 2018 16:00:09 -0700 Subject: [PATCH] Be sure to skip uses of TypeDefinitionAst on both PSV3 and PSV4 --- Engine/Generic/RuleSuppression.cs | 2 +- Engine/Helper.cs | 24 +++++++++++----------- Engine/VariableAnalysis.cs | 2 +- Engine/VariableAnalysisBase.cs | 16 +++++++-------- Rules/DscExamplesPresent.cs | 2 +- Rules/DscTestsPresent.cs | 2 +- Rules/ReturnCorrectTypesForDSCFunctions.cs | 6 +++--- Rules/UseOutputTypeCorrectly.cs | 4 ++-- Rules/UseStandardDSCFunctionsInResource.cs | 2 +- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Engine/Generic/RuleSuppression.cs b/Engine/Generic/RuleSuppression.cs index bdf023096..ac59d43b4 100644 --- a/Engine/Generic/RuleSuppression.cs +++ b/Engine/Generic/RuleSuppression.cs @@ -360,7 +360,7 @@ public static List GetSuppressions(IEnumerable at targetAsts = scopeAst.FindAll(item => item is FunctionDefinitionAst && reg.IsMatch((item as FunctionDefinitionAst).Name), true); goto default; - #if !PSV3 + #if !(PSV3||PSV4) case "class": targetAsts = scopeAst.FindAll(item => item is TypeDefinitionAst && reg.IsMatch((item as TypeDefinitionAst).Name), true); diff --git a/Engine/Helper.cs b/Engine/Helper.cs index 3d1f4a4ad..b093d9c0f 100644 --- a/Engine/Helper.cs +++ b/Engine/Helper.cs @@ -509,7 +509,7 @@ public bool IsDscResourceClassBased(ScriptBlockAst ast) return false; } - #if !PSV3 + #if !(PSV3||PSV4) List dscResourceFunctionNames = new List(new string[] { "Test", "Get", "Set" }); @@ -1018,7 +1018,7 @@ internal VariableAnalysis InitializeVariableAnalysisHelper(Ast ast, VariableAnal /// /// -#if PSV3 +#if (PSV3||PSV4) public string GetTypeFromReturnStatementAst(Ast funcAst, ReturnStatementAst ret) @@ -1089,7 +1089,7 @@ public string GetTypeFromReturnStatementAst(Ast funcAst, ReturnStatementAst ret, /// /// -#if PSV3 +#if (PSV3||PSV4) public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast scopeAst) @@ -1106,7 +1106,7 @@ public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast VariableAnalysisDetails details = null; -#if !PSV3 +#if !(PSV3||PSV4) TypeDefinitionAst psClass = null; @@ -1149,7 +1149,7 @@ public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast /// /// -#if PSV3 +#if (PSV3||PSV4) internal string GetTypeFromMemberExpressionAstHelper(MemberExpressionAst memberAst, VariableAnalysisDetails analysisDetails) @@ -1162,7 +1162,7 @@ internal string GetTypeFromMemberExpressionAstHelper(MemberExpressionAst memberA //Try to get the type without using psClass first Type result = AssignmentTarget.GetTypeFromMemberExpressionAst(memberAst); -#if !PSV3 +#if !(PSV3||PSV4) //If we can't get the type, then it may be that the type of the object being invoked on is a powershell class if (result == null && psClass != null && analysisDetails != null) @@ -1270,7 +1270,7 @@ public Dictionary> GetRuleSuppression(Ast ast) ruleSuppressionList.AddRange(GetSuppressionsFunction(funcAst)); } -#if !PSV3 +#if !(PSV3||PSV4) // Get rule suppression from classes IEnumerable typeAsts = ast.FindAll(item => item is TypeDefinitionAst, true).Cast(); @@ -1322,7 +1322,7 @@ internal List GetSuppressionsFunction(FunctionDefinitionAst fun return result; } -#if !PSV3 +#if !(PSV3||PSV4) /// /// Returns a list of rule suppression from the class /// @@ -2039,7 +2039,7 @@ private object VisitStatementHelper(StatementAst statementAst) return null; } -#if PSV3 +#if (PSV3||PSV4) statementAst.Visit(this); @@ -2755,7 +2755,7 @@ public class FindPipelineOutput : ICustomAstVisitor { List> outputTypes; -#if !PSV3 +#if !(PSV3||PSV4) IEnumerable classes; @@ -2797,7 +2797,7 @@ static FindPipelineOutput() /// /// -#if PSV3 +#if (PSV3||PSV4) public FindPipelineOutput(FunctionDefinitionAst ast) @@ -2828,7 +2828,7 @@ public FindPipelineOutput(FunctionDefinitionAst ast, IEnumerable /// -#if PSV3 +#if (PSV3||PSV4) public static List> OutputTypes(FunctionDefinitionAst funcAst) { diff --git a/Engine/VariableAnalysis.cs b/Engine/VariableAnalysis.cs index 3434a8877..fd66ea2c4 100644 --- a/Engine/VariableAnalysis.cs +++ b/Engine/VariableAnalysis.cs @@ -205,7 +205,7 @@ public void AnalyzeImpl(Ast ast, VariableAnalysis outerAnalysis) parent = parent.Parent; } - #if !PSV3 + #if !(PSV3||PSV4) List classes = parent.FindAll(item => item is TypeDefinitionAst && (item as TypeDefinitionAst).IsClass, true) diff --git a/Engine/VariableAnalysisBase.cs b/Engine/VariableAnalysisBase.cs index 8e366a952..b55119d7a 100644 --- a/Engine/VariableAnalysisBase.cs +++ b/Engine/VariableAnalysisBase.cs @@ -165,7 +165,7 @@ internal void InitializeVariables(Ast ast) _variables.Add("true", new VariableAnalysisDetails { Name = "true", RealName = "true", Type = typeof(bool) }); _variables.Add("false", new VariableAnalysisDetails { Name = "false", RealName = "true", Type = typeof(bool) }); - #if !PSV3 + #if !(PSV3||PSV4) if (ast is FunctionMemberAst) { @@ -808,7 +808,7 @@ internal static void InitializeSSA(Dictionary V /// /// /// - #if PSV3 + #if (PSV3||PSV4) internal static Tuple, Dictionary> SparseSimpleConstants( Dictionary Variables, Block Entry) @@ -989,7 +989,7 @@ internal static Tuple, Dictionary /// - #if PSV3 + #if (PSV3||PSV4) internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memAst, VariableAnalysisDetails analysis) @@ -1460,7 +1460,7 @@ internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memberAs // isStatic is true result = GetTypeFromInvokeMemberAst(type, imeAst, methodName, true); } - #if !PSV3 + #if !(PSV3||PSV4) else { // Check for classes @@ -1498,7 +1498,7 @@ internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memberAs { result = GetPropertyOrFieldTypeFromMemberExpressionAst(expressionType, fieldName); } - #if !PSV3 + #if !(PSV3||PSV4) else { // check for class type @@ -1531,7 +1531,7 @@ internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memberAs if (memberAst.Expression is VariableExpressionAst && String.Equals((memberAst.Expression as VariableExpressionAst).VariablePath.UserPath, "this", StringComparison.OrdinalIgnoreCase)) { - #if !PSV3 + #if !(PSV3||PSV4) // Check that we are in a class TypeDefinitionAst psClass = FindClassAncestor(memberAst); @@ -1598,7 +1598,7 @@ internal static Type GetPropertyOrFieldTypeFromMemberExpressionAst(Type type, st return result; } -#if !PSV3 +#if !(PSV3||PSV4) /// /// Checks whether a class with the name name exists in the script that contains ast /// diff --git a/Rules/DscExamplesPresent.cs b/Rules/DscExamplesPresent.cs index 331991d02..6d0a01a3b 100644 --- a/Rules/DscExamplesPresent.cs +++ b/Rules/DscExamplesPresent.cs @@ -65,7 +65,7 @@ public IEnumerable AnalyzeDSCResource(Ast ast, string fileName } } - #if !PSV3 + #if !(PSV3||PSV4) /// /// AnalyzeDSCClass: Analyzes given DSC class diff --git a/Rules/DscTestsPresent.cs b/Rules/DscTestsPresent.cs index 21dbf10da..5c09ede8a 100644 --- a/Rules/DscTestsPresent.cs +++ b/Rules/DscTestsPresent.cs @@ -65,7 +65,7 @@ public IEnumerable AnalyzeDSCResource(Ast ast, string fileName } } - #if !PSV3 + #if !(PSV3||PSV4) /// /// AnalyzeDSCClass: Analyzes given DSC class diff --git a/Rules/ReturnCorrectTypesForDSCFunctions.cs b/Rules/ReturnCorrectTypesForDSCFunctions.cs index 693b7429f..08eb59df0 100644 --- a/Rules/ReturnCorrectTypesForDSCFunctions.cs +++ b/Rules/ReturnCorrectTypesForDSCFunctions.cs @@ -35,7 +35,7 @@ public IEnumerable AnalyzeDSCResource(Ast ast, string fileName IEnumerable functionDefinitionAsts = Helper.Instance.DscResourceFunctions(ast); - #if !PSV3 + #if !(PSV3||PSV4) IEnumerable classes = ast.FindAll(item => item is TypeDefinitionAst @@ -46,7 +46,7 @@ item is TypeDefinitionAst foreach (FunctionDefinitionAst func in functionDefinitionAsts) { - #if PSV3 + #if PSV3 || PSV4 List> outputTypes = FindPipelineOutput.OutputTypes(func); @@ -93,7 +93,7 @@ item is TypeDefinitionAst } } - #if !PSV3 + #if !(PSV3||PSV4) /// /// AnalyzeDSCClass: Analyzes given DSC Resource diff --git a/Rules/UseOutputTypeCorrectly.cs b/Rules/UseOutputTypeCorrectly.cs index 5d3708ac9..099cd9f25 100644 --- a/Rules/UseOutputTypeCorrectly.cs +++ b/Rules/UseOutputTypeCorrectly.cs @@ -22,7 +22,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules #endif public class UseOutputTypeCorrectly : SkipTypeDefinition, IScriptRule { - #if !PSV3 + #if !(PSV3||PSV4) private IEnumerable _classes; @@ -41,7 +41,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) DiagnosticRecords.Clear(); this.fileName = fileName; - #if !PSV3 + #if !(PSV3||PSV4) _classes = ast.FindAll(item => item is TypeDefinitionAst && ((item as TypeDefinitionAst).IsClass), true).Cast(); diff --git a/Rules/UseStandardDSCFunctionsInResource.cs b/Rules/UseStandardDSCFunctionsInResource.cs index 548414b06..b93147bf7 100644 --- a/Rules/UseStandardDSCFunctionsInResource.cs +++ b/Rules/UseStandardDSCFunctionsInResource.cs @@ -64,7 +64,7 @@ public IEnumerable AnalyzeDSCClass(Ast ast, string fileName) { if (ast == null) throw new ArgumentNullException(Strings.NullAstErrorMessage); - #if PSV3 + #if (PSV3||PSV4) return null;