From f1957dffc549bb50d20150dfa8511f34908d55a9 Mon Sep 17 00:00:00 2001 From: Mikhail Shcherbakov Date: Thu, 26 Aug 2021 19:15:32 +0200 Subject: [PATCH] JS: Run the autoformatter for .qll/.ql files --- .../semmle/javascript/dataflow/DataFlow.qll | 41 ++++++++----------- .../dataflow/internal/DataFlowNode.qll | 4 +- .../dataflow/internal/FlowSteps.qll | 5 ++- .../ql/test/library-tests/Arrays/DataFlow.ql | 2 +- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/javascript/ql/lib/semmle/javascript/dataflow/DataFlow.qll b/javascript/ql/lib/semmle/javascript/dataflow/DataFlow.qll index c17d8b047a9a0..d8ad99c9a11fc 100644 --- a/javascript/ql/lib/semmle/javascript/dataflow/DataFlow.qll +++ b/javascript/ql/lib/semmle/javascript/dataflow/DataFlow.qll @@ -1162,7 +1162,7 @@ module DataFlow { } /** - * A data flow node representing arguments of the `.apply` function call + * A data flow node representing arguments of the `.apply` function call * to emulate a separate argument for each parameter of a reflective function call. */ private class ApplyArgumentNode extends DataFlow::Node { @@ -1171,24 +1171,25 @@ module DataFlow { int index; ApplyArgumentNode() { - this = TApplyArgumentNode( - call.asExpr(), - call.getReceiver().getABoundFunctionValue(_).getFunction(), - index) and + this = + TApplyArgumentNode(call.asExpr(), + call.getReceiver().getABoundFunctionValue(_).getFunction(), index) and arrayArgument = call.getArgument(1) } - /** - * Gets an explicit call of the `.apply` function call - * that takes an argument represented by this data flow node. - * */ + /** + * Gets an explicit call of the `.apply` function call + * that takes an argument represented by this data flow node. + */ ExplicitMethodCallNode getCall() { result = call } /** Gets an argument index represented by this data flow node. */ int getIndex() { result = index } - override string toString() { result = arrayArgument.toString() + "[" + index.toString() + "]" } - + override string toString() { + result = arrayArgument.toString() + "[" + index.toString() + "]" + } + override predicate hasLocationInfo( string filepath, int startline, int startcolumn, int endline, int endcolumn ) { @@ -1199,7 +1200,7 @@ module DataFlow { /** * A data flow node representing a reflective function call. */ - private abstract class ReflectiveCallNodeDef extends CallNodeDef { + abstract private class ReflectiveCallNodeDef extends CallNodeDef { ExplicitMethodCallNode originalCall; override InvokeExpr getInvokeExpr() { result = originalCall.getInvokeExpr() } @@ -1224,17 +1225,13 @@ module DataFlow { } override DataFlow::Node getAnArgument() { - result = originalCall.getAnArgument() and + result = originalCall.getAnArgument() and result != getReceiver() } - override DataFlow::Node getASpreadArgument() { - result = originalCall.getASpreadArgument() - } + override DataFlow::Node getASpreadArgument() { result = originalCall.getASpreadArgument() } - override int getNumArgument() { - result >= 0 and result = originalCall.getNumArgument() - 1 - } + override int getNumArgument() { result >= 0 and result = originalCall.getNumArgument() - 1 } } /** @@ -1244,7 +1241,7 @@ module DataFlow { ApplyReflectiveCallNodeDef() { this = TReflectiveCallNode(originalCall.asExpr(), "apply") } ApplyArgumentNode getApplyArgument(int i) { - result.getCall() = originalCall and + result.getCall() = originalCall and result.getIndex() = i } @@ -1252,9 +1249,7 @@ module DataFlow { override DataFlow::Node getAnArgument() { none() } - override DataFlow::Node getASpreadArgument() { - result = originalCall.getArgument(1) - } + override DataFlow::Node getASpreadArgument() { result = originalCall.getArgument(1) } override int getNumArgument() { none() } } diff --git a/javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowNode.qll b/javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowNode.qll index 4cd9aff73c04f..17e246b8daa2b 100644 --- a/javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowNode.qll +++ b/javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowNode.qll @@ -32,6 +32,4 @@ newtype TNode = TExceptionalInvocationReturnNode(InvokeExpr e) or TGlobalAccessPathRoot() or TTemplatePlaceholderTag(Templating::TemplatePlaceholderTag tag) or - TApplyArgumentNode(MethodCallExpr ce, Function func, int i) { - exists(func.getParameter(i)) - } + TApplyArgumentNode(MethodCallExpr ce, Function func, int i) { exists(func.getParameter(i)) } diff --git a/javascript/ql/lib/semmle/javascript/dataflow/internal/FlowSteps.qll b/javascript/ql/lib/semmle/javascript/dataflow/internal/FlowSteps.qll index 3c683c7dd9a3e..81d59293f943a 100644 --- a/javascript/ql/lib/semmle/javascript/dataflow/internal/FlowSteps.qll +++ b/javascript/ql/lib/semmle/javascript/dataflow/internal/FlowSteps.qll @@ -204,7 +204,10 @@ private module CachedSteps { ) { calls(invk, f) and ( - exists(int i | arg = invk.(DataFlow::InvokeNode).getArgument(i) or arg = invk.(DataFlow::Impl::ApplyReflectiveCallNodeDef).getApplyArgument(i) | + exists(int i | + arg = invk.(DataFlow::InvokeNode).getArgument(i) or + arg = invk.(DataFlow::Impl::ApplyReflectiveCallNodeDef).getApplyArgument(i) + | exists(Parameter p | f.getParameter(i) = p and not p.isRestParameter() and diff --git a/javascript/ql/test/library-tests/Arrays/DataFlow.ql b/javascript/ql/test/library-tests/Arrays/DataFlow.ql index 751fb18b692e9..11a0a67b2d59d 100644 --- a/javascript/ql/test/library-tests/Arrays/DataFlow.ql +++ b/javascript/ql/test/library-tests/Arrays/DataFlow.ql @@ -12,4 +12,4 @@ class ArrayFlowConfig extends DataFlow::Configuration { from ArrayFlowConfig config, DataFlow::Node src, DataFlow::Node snk, string snk_file where config.hasFlow(src, snk) and snk_file = snk.getAstNode().getFile().getBaseName() -select snk_file, snk, src \ No newline at end of file +select snk_file, snk, src