Skip to content

Commit

Permalink
Be sure to skip uses of TypeDefinitionAst on both PSV3 and PSV4
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWTruher committed Oct 18, 2018
1 parent 9ef4a9d commit e9c8175
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Engine/Generic/RuleSuppression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public static List<RuleSuppression> GetSuppressions(IEnumerable<AttributeAst> 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);
Expand Down
24 changes: 12 additions & 12 deletions Engine/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public bool IsDscResourceClassBased(ScriptBlockAst ast)
return false;
}

#if !PSV3
#if !(PSV3||PSV4)

List<string> dscResourceFunctionNames = new List<string>(new string[] { "Test", "Get", "Set" });

Expand Down Expand Up @@ -1018,7 +1018,7 @@ internal VariableAnalysis InitializeVariableAnalysisHelper(Ast ast, VariableAnal
/// <param name="scriptAst"></param>
/// <returns></returns>

#if PSV3
#if (PSV3||PSV4)

public string GetTypeFromReturnStatementAst(Ast funcAst, ReturnStatementAst ret)

Expand Down Expand Up @@ -1089,7 +1089,7 @@ public string GetTypeFromReturnStatementAst(Ast funcAst, ReturnStatementAst ret,
/// <param name="classes"></param>
/// <returns></returns>

#if PSV3
#if (PSV3||PSV4)

public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast scopeAst)

Expand All @@ -1106,7 +1106,7 @@ public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast

VariableAnalysisDetails details = null;

#if !PSV3
#if !(PSV3||PSV4)

TypeDefinitionAst psClass = null;

Expand Down Expand Up @@ -1149,7 +1149,7 @@ public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast
/// <param name="analysisDetails"></param>
/// <returns></returns>

#if PSV3
#if (PSV3||PSV4)

internal string GetTypeFromMemberExpressionAstHelper(MemberExpressionAst memberAst, VariableAnalysisDetails analysisDetails)

Expand All @@ -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)
Expand Down Expand Up @@ -1270,7 +1270,7 @@ public Dictionary<string, List<RuleSuppression>> GetRuleSuppression(Ast ast)
ruleSuppressionList.AddRange(GetSuppressionsFunction(funcAst));
}

#if !PSV3
#if !(PSV3||PSV4)
// Get rule suppression from classes
IEnumerable<TypeDefinitionAst> typeAsts = ast.FindAll(item => item is TypeDefinitionAst, true).Cast<TypeDefinitionAst>();

Expand Down Expand Up @@ -1322,7 +1322,7 @@ internal List<RuleSuppression> GetSuppressionsFunction(FunctionDefinitionAst fun
return result;
}

#if !PSV3
#if !(PSV3||PSV4)
/// <summary>
/// Returns a list of rule suppression from the class
/// </summary>
Expand Down Expand Up @@ -2039,7 +2039,7 @@ private object VisitStatementHelper(StatementAst statementAst)
return null;
}

#if PSV3
#if (PSV3||PSV4)

statementAst.Visit(this);

Expand Down Expand Up @@ -2755,7 +2755,7 @@ public class FindPipelineOutput : ICustomAstVisitor
{
List<Tuple<string, StatementAst>> outputTypes;

#if !PSV3
#if !(PSV3||PSV4)

IEnumerable<TypeDefinitionAst> classes;

Expand Down Expand Up @@ -2797,7 +2797,7 @@ static FindPipelineOutput()
/// </summary>
/// <param name="ast"></param>

#if PSV3
#if (PSV3||PSV4)

public FindPipelineOutput(FunctionDefinitionAst ast)

Expand Down Expand Up @@ -2828,7 +2828,7 @@ public FindPipelineOutput(FunctionDefinitionAst ast, IEnumerable<TypeDefinitionA
/// </summary>
/// <returns></returns>

#if PSV3
#if (PSV3||PSV4)

public static List<Tuple<string, StatementAst>> OutputTypes(FunctionDefinitionAst funcAst)
{
Expand Down
2 changes: 1 addition & 1 deletion Engine/VariableAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void AnalyzeImpl(Ast ast, VariableAnalysis outerAnalysis)
parent = parent.Parent;
}

#if !PSV3
#if !(PSV3||PSV4)

List<TypeDefinitionAst> classes = parent.FindAll(item =>
item is TypeDefinitionAst && (item as TypeDefinitionAst).IsClass, true)
Expand Down
16 changes: 8 additions & 8 deletions Engine/VariableAnalysisBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -808,7 +808,7 @@ internal static void InitializeSSA(Dictionary<string, VariableAnalysisDetails> V
/// <param name="Entry"></param>
/// <param name="Classes"></param>
/// <returns></returns>
#if PSV3
#if (PSV3||PSV4)

internal static Tuple<Dictionary<string, VariableAnalysisDetails>, Dictionary<string, VariableAnalysisDetails>> SparseSimpleConstants(
Dictionary<string, VariableAnalysisDetails> Variables, Block Entry)
Expand Down Expand Up @@ -989,7 +989,7 @@ internal static Tuple<Dictionary<string, VariableAnalysisDetails>, Dictionary<st
{
VariableAnalysisDetails analysis = VariablesDictionary[VariableAnalysis.AnalysisDictionaryKey(memAst.Expression as VariableExpressionAst)];

#if PSV3
#if (PSV3||PSV4)

Type possibleType = AssignmentTarget.GetTypeFromMemberExpressionAst(memAst, analysis);

Expand Down Expand Up @@ -1371,7 +1371,7 @@ public AssignmentTarget(string variableName, Type type)
/// <param name="psClass"></param>
/// <returns></returns>

#if PSV3
#if (PSV3||PSV4)

internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memAst, VariableAnalysisDetails analysis)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1498,7 +1498,7 @@ internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memberAs
{
result = GetPropertyOrFieldTypeFromMemberExpressionAst(expressionType, fieldName);
}
#if !PSV3
#if !(PSV3||PSV4)
else
{
// check for class type
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1598,7 +1598,7 @@ internal static Type GetPropertyOrFieldTypeFromMemberExpressionAst(Type type, st
return result;
}

#if !PSV3
#if !(PSV3||PSV4)
/// <summary>
/// Checks whether a class with the name name exists in the script that contains ast
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Rules/DscExamplesPresent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName
}
}

#if !PSV3
#if !(PSV3||PSV4)

/// <summary>
/// AnalyzeDSCClass: Analyzes given DSC class
Expand Down
2 changes: 1 addition & 1 deletion Rules/DscTestsPresent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName
}
}

#if !PSV3
#if !(PSV3||PSV4)

/// <summary>
/// AnalyzeDSCClass: Analyzes given DSC class
Expand Down
6 changes: 3 additions & 3 deletions Rules/ReturnCorrectTypesForDSCFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName

IEnumerable<Ast> functionDefinitionAsts = Helper.Instance.DscResourceFunctions(ast);

#if !PSV3
#if !(PSV3||PSV4)

IEnumerable<TypeDefinitionAst> classes = ast.FindAll(item =>
item is TypeDefinitionAst
Expand All @@ -46,7 +46,7 @@ item is TypeDefinitionAst
foreach (FunctionDefinitionAst func in functionDefinitionAsts)
{

#if PSV3
#if PSV3 || PSV4

List<Tuple<string, StatementAst>> outputTypes = FindPipelineOutput.OutputTypes(func);

Expand Down Expand Up @@ -93,7 +93,7 @@ item is TypeDefinitionAst
}
}

#if !PSV3
#if !(PSV3||PSV4)

/// <summary>
/// AnalyzeDSCClass: Analyzes given DSC Resource
Expand Down
4 changes: 2 additions & 2 deletions Rules/UseOutputTypeCorrectly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
#endif
public class UseOutputTypeCorrectly : SkipTypeDefinition, IScriptRule
{
#if !PSV3
#if !(PSV3||PSV4)

private IEnumerable<TypeDefinitionAst> _classes;

Expand All @@ -41,7 +41,7 @@ public IEnumerable<DiagnosticRecord> 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<TypeDefinitionAst>();

Expand Down
2 changes: 1 addition & 1 deletion Rules/UseStandardDSCFunctionsInResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCClass(Ast ast, string fileName)
{
if (ast == null) throw new ArgumentNullException(Strings.NullAstErrorMessage);

#if PSV3
#if (PSV3||PSV4)

return null;

Expand Down

0 comments on commit e9c8175

Please sign in to comment.