JavaScript: ignore self-assignments with a JSDoc comment

This commit is contained in:
Asger F
2018-09-06 16:31:10 +01:00
parent 2846d80f1c
commit 4f4ad2b942
4 changed files with 29 additions and 3 deletions

View File

@@ -152,7 +152,14 @@ class SelfAssignment extends StructurallyCompared {
}
override Expr candidate() {
result = getParent().(AssignExpr).getRhs()
result = getAssignment().getRhs()
}
/**
* Gets the enclosing assignment.
*/
AssignExpr getAssignment() {
result.getLhs() = this
}
}

View File

@@ -43,5 +43,7 @@ where e.same(_) and
propName = any(AccessorMethodDeclaration amd).getName()
) and
// exclude DOM properties
not isDOMProperty(e.(PropAccess).getPropertyName())
select e.getParent(), "This expression assigns " + dsc + " to itself."
not isDOMProperty(e.(PropAccess).getPropertyName()) and
// exclude self-assignments with a JSDoc comment
not exists(e.getAssignment().getParent().(ExprStmt).getDocumentation().getATag())
select e.getParent(), "This expression assigns " + dsc + " to itself."