-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathReturnAssignsLocal.qhelp
More file actions
43 lines (35 loc) · 1.31 KB
/
ReturnAssignsLocal.qhelp
File metadata and controls
43 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
Assigning a local variable in a return statement is useless, since the local variable will go out
of scope immediately and its new value is lost.
</p>
</overview>
<recommendation>
<p>
Closely examine the code in question to understand the original intention. For instance, the assignment
may originally have referred to a variable from another scope that accidentally was shadowed due to
a renaming; in this case, perform another renaming to make it visible again. Or maybe the assignment
was meant to assign to a property of the receiver object and the programmer inadvertently forgot to
qualify it by <code>this</code>; address this by providing the required qualification. Finally, the
assignment may simply be unnecessary, in which case it can be removed.
</p>
</recommendation>
<example>
<p>
In the following example, the <code>getName</code> method of <code>Person</code> contains a useless
assignment to <code>name</code>.
</p>
<sample src="examples/ReturnAssignsLocal.js" />
<p>
The assignment serves no obvious purpose and should be removed:
</p>
<sample src="examples/ReturnAssignsLocalGood.js" />
</example>
<references>
<li>Wikipedia: <a href="https://en.wikipedia.org/wiki/Dead_store">Dead store</a>.</li>
</references>
</qhelp>