Skip to content

Commit 503d18e

Browse files
committed
Don't trigger PSAvoidUninitializedVariable on function parameters
1 parent 513b04c commit 503d18e

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Rules/AvoidUninitializedVariable.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
5656
// Checks whether this is a dsc resource file (we don't raise this rule for get, set and test-target resource
5757
bool isDscResourceFile = Helper.Instance.IsDscResourceModule(fileName);
5858

59-
List<string> targetResourcesFunctions = new List<string>( new string[] { "get-targetresource", "set-targetresource", "test-targetresource" });
59+
List<string> targetResourcesFunctions = new List<string>(new string[] { "get-targetresource", "set-targetresource", "test-targetresource" });
6060

6161
foreach (FunctionDefinitionAst funcAst in funcAsts)
6262
{
@@ -65,13 +65,10 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
6565

6666
HashSet<string> paramVariables = new HashSet<string>();
6767

68-
if (isDscResourceFile && targetResourcesFunctions.Contains(funcAst.Name, StringComparer.OrdinalIgnoreCase))
68+
// don't raise the rules for variables in the param block.
69+
if (funcAst.Body != null && funcAst.Body.ParamBlock != null && funcAst.Body.ParamBlock.Parameters != null)
6970
{
70-
// don't raise the rules for variables in the param block.
71-
if (funcAst.Body != null && funcAst.Body.ParamBlock != null && funcAst.Body.ParamBlock.Parameters != null)
72-
{
73-
paramVariables.UnionWith(funcAst.Body.ParamBlock.Parameters.Select(paramAst => paramAst.Name.VariablePath.UserPath));
74-
}
71+
paramVariables.UnionWith(funcAst.Body.ParamBlock.Parameters.Select(paramAst => paramAst.Name.VariablePath.UserPath));
7572
}
7673

7774
// Iterates all VariableExpressionAst and check the command name.

0 commit comments

Comments
 (0)