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

Skip to content

Commit 4f4ad2b

Browse files
committed
JavaScript: ignore self-assignments with a JSDoc comment
1 parent 2846d80 commit 4f4ad2b

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

javascript/ql/src/Expressions/Clones.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ class SelfAssignment extends StructurallyCompared {
152152
}
153153

154154
override Expr candidate() {
155-
result = getParent().(AssignExpr).getRhs()
155+
result = getAssignment().getRhs()
156+
}
157+
158+
/**
159+
* Gets the enclosing assignment.
160+
*/
161+
AssignExpr getAssignment() {
162+
result.getLhs() = this
156163
}
157164
}
158165

javascript/ql/src/Expressions/SelfAssignment.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@ where e.same(_) and
4343
propName = any(AccessorMethodDeclaration amd).getName()
4444
) and
4545
// exclude DOM properties
46-
not isDOMProperty(e.(PropAccess).getPropertyName())
47-
select e.getParent(), "This expression assigns " + dsc + " to itself."
46+
not isDOMProperty(e.(PropAccess).getPropertyName()) and
47+
// exclude self-assignments with a JSDoc comment
48+
not exists(e.getAssignment().getParent().(ExprStmt).getDocumentation().getATag())
49+
select e.getParent(), "This expression assigns " + dsc + " to itself."
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
| jsdoc.js:9:5:9:19 | this.y = this.y | This expression assigns property y to itself. |
2+
| jsdoc.js:11:5:11:23 | this.arg = this.arg | This expression assigns property arg to itself. |
13
| tst.js:5:2:5:14 | width = width | This expression assigns variable width to itself. |
24
| tst.js:24:1:24:19 | array[1] = array[1] | This expression assigns element 1 to itself. |
35
| tst.js:27:1:27:9 | o.x = o.x | This expression assigns property x to itself. |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class C extends Q {
2+
constructor(arg) {
3+
/**
4+
* Something.
5+
* @type {string | undefined}
6+
*/
7+
this.x = this.x; // OK - documentation
8+
9+
this.y = this.y; // NOT OK
10+
11+
this.arg = this.arg; // NOT OK
12+
}
13+
}
14+
15+
// semmle-extractor-options: --experimental

0 commit comments

Comments
 (0)