Skip to content

Commit e9c8175

Browse files
committed
Be sure to skip uses of TypeDefinitionAst on both PSV3 and PSV4
1 parent 9ef4a9d commit e9c8175

9 files changed

+30
-30
lines changed

Engine/Generic/RuleSuppression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public static List<RuleSuppression> GetSuppressions(IEnumerable<AttributeAst> at
360360
targetAsts = scopeAst.FindAll(item => item is FunctionDefinitionAst && reg.IsMatch((item as FunctionDefinitionAst).Name), true);
361361
goto default;
362362

363-
#if !PSV3
363+
#if !(PSV3||PSV4)
364364

365365
case "class":
366366
targetAsts = scopeAst.FindAll(item => item is TypeDefinitionAst && reg.IsMatch((item as TypeDefinitionAst).Name), true);

Engine/Helper.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ public bool IsDscResourceClassBased(ScriptBlockAst ast)
509509
return false;
510510
}
511511

512-
#if !PSV3
512+
#if !(PSV3||PSV4)
513513

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

@@ -1018,7 +1018,7 @@ internal VariableAnalysis InitializeVariableAnalysisHelper(Ast ast, VariableAnal
10181018
/// <param name="scriptAst"></param>
10191019
/// <returns></returns>
10201020

1021-
#if PSV3
1021+
#if (PSV3||PSV4)
10221022

10231023
public string GetTypeFromReturnStatementAst(Ast funcAst, ReturnStatementAst ret)
10241024

@@ -1089,7 +1089,7 @@ public string GetTypeFromReturnStatementAst(Ast funcAst, ReturnStatementAst ret,
10891089
/// <param name="classes"></param>
10901090
/// <returns></returns>
10911091

1092-
#if PSV3
1092+
#if (PSV3||PSV4)
10931093

10941094
public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast scopeAst)
10951095

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

11071107
VariableAnalysisDetails details = null;
11081108

1109-
#if !PSV3
1109+
#if !(PSV3||PSV4)
11101110

11111111
TypeDefinitionAst psClass = null;
11121112

@@ -1149,7 +1149,7 @@ public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast
11491149
/// <param name="analysisDetails"></param>
11501150
/// <returns></returns>
11511151

1152-
#if PSV3
1152+
#if (PSV3||PSV4)
11531153

11541154
internal string GetTypeFromMemberExpressionAstHelper(MemberExpressionAst memberAst, VariableAnalysisDetails analysisDetails)
11551155

@@ -1162,7 +1162,7 @@ internal string GetTypeFromMemberExpressionAstHelper(MemberExpressionAst memberA
11621162
//Try to get the type without using psClass first
11631163
Type result = AssignmentTarget.GetTypeFromMemberExpressionAst(memberAst);
11641164

1165-
#if !PSV3
1165+
#if !(PSV3||PSV4)
11661166

11671167
//If we can't get the type, then it may be that the type of the object being invoked on is a powershell class
11681168
if (result == null && psClass != null && analysisDetails != null)
@@ -1270,7 +1270,7 @@ public Dictionary<string, List<RuleSuppression>> GetRuleSuppression(Ast ast)
12701270
ruleSuppressionList.AddRange(GetSuppressionsFunction(funcAst));
12711271
}
12721272

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

@@ -1322,7 +1322,7 @@ internal List<RuleSuppression> GetSuppressionsFunction(FunctionDefinitionAst fun
13221322
return result;
13231323
}
13241324

1325-
#if !PSV3
1325+
#if !(PSV3||PSV4)
13261326
/// <summary>
13271327
/// Returns a list of rule suppression from the class
13281328
/// </summary>
@@ -2039,7 +2039,7 @@ private object VisitStatementHelper(StatementAst statementAst)
20392039
return null;
20402040
}
20412041

2042-
#if PSV3
2042+
#if (PSV3||PSV4)
20432043

20442044
statementAst.Visit(this);
20452045

@@ -2755,7 +2755,7 @@ public class FindPipelineOutput : ICustomAstVisitor
27552755
{
27562756
List<Tuple<string, StatementAst>> outputTypes;
27572757

2758-
#if !PSV3
2758+
#if !(PSV3||PSV4)
27592759

27602760
IEnumerable<TypeDefinitionAst> classes;
27612761

@@ -2797,7 +2797,7 @@ static FindPipelineOutput()
27972797
/// </summary>
27982798
/// <param name="ast"></param>
27992799

2800-
#if PSV3
2800+
#if (PSV3||PSV4)
28012801

28022802
public FindPipelineOutput(FunctionDefinitionAst ast)
28032803

@@ -2828,7 +2828,7 @@ public FindPipelineOutput(FunctionDefinitionAst ast, IEnumerable<TypeDefinitionA
28282828
/// </summary>
28292829
/// <returns></returns>
28302830

2831-
#if PSV3
2831+
#if (PSV3||PSV4)
28322832

28332833
public static List<Tuple<string, StatementAst>> OutputTypes(FunctionDefinitionAst funcAst)
28342834
{

Engine/VariableAnalysis.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public void AnalyzeImpl(Ast ast, VariableAnalysis outerAnalysis)
205205
parent = parent.Parent;
206206
}
207207

208-
#if !PSV3
208+
#if !(PSV3||PSV4)
209209

210210
List<TypeDefinitionAst> classes = parent.FindAll(item =>
211211
item is TypeDefinitionAst && (item as TypeDefinitionAst).IsClass, true)

Engine/VariableAnalysisBase.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ internal void InitializeVariables(Ast ast)
165165
_variables.Add("true", new VariableAnalysisDetails { Name = "true", RealName = "true", Type = typeof(bool) });
166166
_variables.Add("false", new VariableAnalysisDetails { Name = "false", RealName = "true", Type = typeof(bool) });
167167

168-
#if !PSV3
168+
#if !(PSV3||PSV4)
169169

170170
if (ast is FunctionMemberAst)
171171
{
@@ -808,7 +808,7 @@ internal static void InitializeSSA(Dictionary<string, VariableAnalysisDetails> V
808808
/// <param name="Entry"></param>
809809
/// <param name="Classes"></param>
810810
/// <returns></returns>
811-
#if PSV3
811+
#if (PSV3||PSV4)
812812

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

992-
#if PSV3
992+
#if (PSV3||PSV4)
993993

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

@@ -1371,7 +1371,7 @@ public AssignmentTarget(string variableName, Type type)
13711371
/// <param name="psClass"></param>
13721372
/// <returns></returns>
13731373

1374-
#if PSV3
1374+
#if (PSV3||PSV4)
13751375

13761376
internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memAst, VariableAnalysisDetails analysis)
13771377

@@ -1460,7 +1460,7 @@ internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memberAs
14601460
// isStatic is true
14611461
result = GetTypeFromInvokeMemberAst(type, imeAst, methodName, true);
14621462
}
1463-
#if !PSV3
1463+
#if !(PSV3||PSV4)
14641464
else
14651465
{
14661466
// Check for classes
@@ -1498,7 +1498,7 @@ internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memberAs
14981498
{
14991499
result = GetPropertyOrFieldTypeFromMemberExpressionAst(expressionType, fieldName);
15001500
}
1501-
#if !PSV3
1501+
#if !(PSV3||PSV4)
15021502
else
15031503
{
15041504
// check for class type
@@ -1531,7 +1531,7 @@ internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memberAs
15311531
if (memberAst.Expression is VariableExpressionAst
15321532
&& String.Equals((memberAst.Expression as VariableExpressionAst).VariablePath.UserPath, "this", StringComparison.OrdinalIgnoreCase))
15331533
{
1534-
#if !PSV3
1534+
#if !(PSV3||PSV4)
15351535

15361536
// Check that we are in a class
15371537
TypeDefinitionAst psClass = FindClassAncestor(memberAst);
@@ -1598,7 +1598,7 @@ internal static Type GetPropertyOrFieldTypeFromMemberExpressionAst(Type type, st
15981598
return result;
15991599
}
16001600

1601-
#if !PSV3
1601+
#if !(PSV3||PSV4)
16021602
/// <summary>
16031603
/// Checks whether a class with the name name exists in the script that contains ast
16041604
/// </summary>

Rules/DscExamplesPresent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName
6565
}
6666
}
6767

68-
#if !PSV3
68+
#if !(PSV3||PSV4)
6969

7070
/// <summary>
7171
/// AnalyzeDSCClass: Analyzes given DSC class

Rules/DscTestsPresent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName
6565
}
6666
}
6767

68-
#if !PSV3
68+
#if !(PSV3||PSV4)
6969

7070
/// <summary>
7171
/// AnalyzeDSCClass: Analyzes given DSC class

Rules/ReturnCorrectTypesForDSCFunctions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName
3535

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

38-
#if !PSV3
38+
#if !(PSV3||PSV4)
3939

4040
IEnumerable<TypeDefinitionAst> classes = ast.FindAll(item =>
4141
item is TypeDefinitionAst
@@ -46,7 +46,7 @@ item is TypeDefinitionAst
4646
foreach (FunctionDefinitionAst func in functionDefinitionAsts)
4747
{
4848

49-
#if PSV3
49+
#if PSV3 || PSV4
5050

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

@@ -93,7 +93,7 @@ item is TypeDefinitionAst
9393
}
9494
}
9595

96-
#if !PSV3
96+
#if !(PSV3||PSV4)
9797

9898
/// <summary>
9999
/// AnalyzeDSCClass: Analyzes given DSC Resource

Rules/UseOutputTypeCorrectly.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
2222
#endif
2323
public class UseOutputTypeCorrectly : SkipTypeDefinition, IScriptRule
2424
{
25-
#if !PSV3
25+
#if !(PSV3||PSV4)
2626

2727
private IEnumerable<TypeDefinitionAst> _classes;
2828

@@ -41,7 +41,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
4141
DiagnosticRecords.Clear();
4242
this.fileName = fileName;
4343

44-
#if !PSV3
44+
#if !(PSV3||PSV4)
4545

4646
_classes = ast.FindAll(item => item is TypeDefinitionAst && ((item as TypeDefinitionAst).IsClass), true).Cast<TypeDefinitionAst>();
4747

Rules/UseStandardDSCFunctionsInResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCClass(Ast ast, string fileName)
6464
{
6565
if (ast == null) throw new ArgumentNullException(Strings.NullAstErrorMessage);
6666

67-
#if PSV3
67+
#if (PSV3||PSV4)
6868

6969
return null;
7070

0 commit comments

Comments
 (0)