mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
changes to documentation and small change in returnsVoid based on code-review
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<qhelp>
|
||||
<overview>
|
||||
<p>
|
||||
JavaScript functions that do not return any value will implicitly return
|
||||
JavaScript functions that do not return an expression will implicitly return
|
||||
<code>undefined</code>. Using the implicit return value from such a function
|
||||
is not an error in itself, but it is a pattern indicating that some
|
||||
misunderstanding has occurred.
|
||||
@@ -14,8 +14,7 @@ misunderstanding has occurred.
|
||||
<recommendation>
|
||||
|
||||
<p>
|
||||
Do not use the return value from a function that does not explicitly return
|
||||
a value.
|
||||
Do not use the return value from a function that does not return an expression.
|
||||
</p>
|
||||
|
||||
</recommendation>
|
||||
@@ -23,10 +22,10 @@ a value.
|
||||
|
||||
<p>
|
||||
In the example below, the function <code>renderText</code> is used to render
|
||||
text through side effects, and the function does not return a value.
|
||||
text through side effects, and the function does not return an expression.
|
||||
However, the programmer still uses the return value from
|
||||
<code>renderText</code> as if the function returned a value, which is clearly
|
||||
an error.
|
||||
<code>renderText</code> as if the function returned an expression, which is
|
||||
clearly an error.
|
||||
</p>
|
||||
|
||||
<sample src="examples/UseOfReturnlessFunction.js" />
|
||||
@@ -34,7 +33,7 @@ an error.
|
||||
<p>
|
||||
The program can be fixed either removing the use of the value returned by
|
||||
<code>renderText</code>, or by changing the <code>renderText</code> method
|
||||
to return a value.
|
||||
to return an expression.
|
||||
</p>
|
||||
|
||||
</example>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @name Use of returnless function
|
||||
* @description Using the return value of a function that does not explicitly return is indicative of a mistake.
|
||||
* @description Using the return value of a function that does not return an expression is indicative of a mistake.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @id js/use-of-returnless-function
|
||||
@@ -15,7 +15,7 @@ import Expressions.ExprHasNoEffect
|
||||
import Statements.UselessConditional
|
||||
|
||||
predicate returnsVoid(Function f) {
|
||||
f.getBody() instanceof Stmt and
|
||||
not f instanceof ArrowFunctionExpr and
|
||||
not f.isGenerator() and
|
||||
not f.isAsync() and
|
||||
not exists(f.getAReturnedExpr())
|
||||
|
||||
@@ -124,8 +124,6 @@ predicate whitelist(Expr e) {
|
||||
isConstantBooleanReturnValue(e)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Holds if `e` is part of a conditional node `cond` that evaluates
|
||||
* `e` and checks its value for truthiness.
|
||||
|
||||
Reference in New Issue
Block a user