Skip to content

Fix use declared vars more than assignment #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Rules/UseDeclaredVarsMoreThanAssignments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
{
foreach (AssignmentStatementAst assignmentAst in assignmentAsts)
{
assingmentVarAsts = assignmentAst.Left.FindAll(testAst => testAst is VariableExpressionAst, true); ;
// Only checks for the case where lhs is a variable. Ignore things like $foo.property
VariableExpressionAst assignmentVarAst = assignmentAst.Left as VariableExpressionAst;

foreach (VariableExpressionAst assignmentVarAst in assingmentVarAsts)
if (assignmentVarAst != null)
{
//Ignore if variable is global or environment variable
if (!Helper.Instance.IsVariableGlobalOrEnvironment(assignmentVarAst, ast))
//Ignore if variable is global or environment variable
if (!Helper.Instance.IsVariableGlobalOrEnvironment(assignmentVarAst, ast)
&& !assignmentVarAst.VariablePath.IsScript)
{
if (!assignments.ContainsKey(assignmentVarAst.VariablePath.UserPath))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
$declaredVars = "Declared Vars"
Write-Ouput $declaredVars
Write-Ouput $declaredVars
$script:thisshouldnotraiseerrors = "this should not raise errors"
$foo.property = "This also should not raise errors"