Skip to content

Commit 7adb020

Browse files
committed
PS: Remove arguments that are just names for a named argument.
1 parent 3bb6021 commit 7adb020

File tree

1 file changed

+39
-0
lines changed
  • powershell/ql/lib/semmle/code/powershell/ast/internal

1 file changed

+39
-0
lines changed

powershell/ql/lib/semmle/code/powershell/ast/internal/Synthesis.qll

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,42 @@ private module CmdExprRemoval {
528528
}
529529
}
530530
}
531+
532+
/**
533+
* Clean up arguments to commands by:
534+
* - Removing the parameter name as an argument.
535+
*/
536+
private module CmdArguments {
537+
private class CmdParameterRemoval extends Synthesis {
538+
override predicate child(Raw::Ast parent, ChildIndex i, Child child) {
539+
exists(Raw::Expr e |
540+
this.rawChild(parent, i, e) and
541+
child = childRef(getResultAst(e))
542+
)
543+
}
544+
545+
private predicate rawChild(Raw::Cmd cmd, ChildIndex i, Raw::Expr child) {
546+
exists(int index |
547+
i = cmdArgument(index) and
548+
child = cmd.getArgument(index)
549+
)
550+
}
551+
552+
override predicate isNamedArgument(CmdCall call, int i, string name) {
553+
exists(Raw::Cmd cmd, Raw::Expr e, Raw::CmdParameter p |
554+
this.rawChild(cmd, cmdArgument(i), e) and
555+
call = getResultAst(cmd) and
556+
p.getName().toLowerCase() = name
557+
|
558+
p.getExpr() = e
559+
or
560+
exists(ChildIndex j, int jndex |
561+
j = cmdElement_(jndex) and
562+
not exists(p.getExpr()) and
563+
cmd.getChild(toRawChildIndex(j)) = p and
564+
cmd.getChild(toRawChildIndex(cmdElement_(jndex + 1))) = e
565+
)
566+
)
567+
}
568+
}
569+
}

0 commit comments

Comments
 (0)