Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34d0f72

Browse files
committed
small refactor and added docstring based on code review
1 parent 92623a3 commit 34d0f72

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

javascript/ql/src/Statements/UseOfReturnlessFunction.ql

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ predicate benignContext(Expr e) {
3333

3434
// A return statement is often used to just end the function.
3535
e = any(Function f).getAReturnedExpr()
36-
or
37-
// The call is only in a non-void context because it is in a lambda.
38-
e = any(ArrowFunctionExpr arrow).getBody()
3936
or
4037
exists(ConditionalExpr cond | cond.getABranch() = e and benignContext(cond))
4138
or
@@ -47,31 +44,31 @@ predicate benignContext(Expr e) {
4744
or
4845
exists(Expr parent | parent.getUnderlyingValue() = e and benignContext(parent))
4946
or
50-
exists(VoidExpr voidExpr | voidExpr.getOperand() = e)
47+
any(VoidExpr voidExpr).getOperand() = e
5148

5249
or
5350
// weeds out calls inside HTML-attributes.
54-
e.getContainer() instanceof CodeInAttribute or
51+
e.getParent() instanceof CodeInAttribute or
5552
// and JSX-attributes.
5653
e = any(JSXAttribute attr).getValue() or
5754

5855
// It is ok (or to be flagged by another query?) to await a non-async function.
5956
exists(AwaitExpr await | await.getOperand() = e and benignContext(await))
6057
or
6158
// Avoid double reporting with js/trivial-conditional
62-
exists(ASTNode cond | isExplicitConditional(cond, e))
59+
isExplicitConditional(_, e)
6360
or
6461
// Avoid double reporting with js/comparison-between-incompatible-types
65-
exists(Comparison binOp | binOp.getAnOperand() = e)
62+
any(Comparison binOp).getAnOperand() = e
6663
or
6764
// Avoid double reporting with js/property-access-on-non-object
68-
exists(PropAccess ac | ac.getBase() = e)
65+
any(PropAccess ac).getBase() = e
6966
or
7067
// Avoid double-reporting with js/unused-local-variable
7168
exists(VariableDeclarator v | v.getInit() = e and v.getBindingPattern().getVariable() instanceof UnusedLocal)
7269
or
7370
// Avoid double reporting with js/call-to-non-callable
74-
exists(InvokeExpr invoke | invoke.getCallee() = e)
71+
any(InvokeExpr invoke).getCallee() = e
7572
}
7673

7774
predicate functionBlacklist(Function f) {

javascript/ql/src/Statements/UselessConditional.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides predicates for working with useless conditionals.
3+
*/
4+
15
import javascript
26

37
/**

0 commit comments

Comments
 (0)