mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Merge pull request #166 from asger-semmle/documentable-self-assign
Approved by esben-semmle, xiemaisi
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ Assigning a variable to itself typically indicates a mistake such as a missing
|
||||
Carefully inspect the assignment to check for misspellings or missing qualifiers.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If the self-assignment is intentional and is needed for documentation or optimization purposes,
|
||||
add a JSDoc comment with a <tt>@type</tt> tag. This will indicate the self-assignment is intentional.
|
||||
</p>
|
||||
|
||||
</recommendation>
|
||||
<example>
|
||||
|
||||
|
||||
@@ -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 that have been inserted to satisfy the TypeScript JS-checker
|
||||
not e.getAssignment().getParent().(ExprStmt).getDocumentation().getATag().getTitle() = "type"
|
||||
select e.getParent(), "This expression assigns " + dsc + " to itself."
|
||||
|
||||
Reference in New Issue
Block a user