add explicit this to all member calls

This commit is contained in:
Erik Krogh Kristensen
2021-11-01 09:51:15 +01:00
parent 1c78c792ff
commit db40ccae81
85 changed files with 2063 additions and 1937 deletions

View File

@@ -61,9 +61,9 @@ abstract class StructurallyCompared extends ASTNode {
ASTNode candidateInternal() {
// in order to correspond, nodes need to have the same kind and shape
exists(int kind, int numChildren | kindAndArity(this, kind, numChildren) |
result = candidateKind(kind, numChildren)
result = this.candidateKind(kind, numChildren)
or
result = uncleKind(kind, numChildren)
result = this.uncleKind(kind, numChildren)
)
}
@@ -78,12 +78,12 @@ abstract class StructurallyCompared extends ASTNode {
}
private ASTNode candidateKind(int kind, int numChildren) {
result = candidate() and kindAndArity(result, kind, numChildren)
result = this.candidate() and kindAndArity(result, kind, numChildren)
}
pragma[noinline]
private ASTNode uncleKind(int kind, int numChildren) {
exists(int i | result = getAStructuralUncle(i).getChild(i)) and
exists(int i | result = this.getAStructuralUncle(i).getChild(i)) and
kindAndArity(result, kind, numChildren)
}
@@ -109,7 +109,7 @@ abstract class StructurallyCompared extends ASTNode {
(exists(valueOf(this)) implies valueOf(this) = valueOf(that)) and
forall(StructurallyCompared child, int i |
child = getChild(i) and that = child.getAStructuralUncle(i)
child = this.getChild(i) and that = child.getAStructuralUncle(i)
|
child.sameInternal(that.getChild(i))
)
@@ -130,7 +130,7 @@ abstract class StructurallyCompared extends ASTNode {
* A child of a node that is subject to structural comparison.
*/
private class InternalCandidate extends StructurallyCompared {
InternalCandidate() { exists(getParent().(StructurallyCompared).candidateInternal()) }
InternalCandidate() { exists(this.getParent().(StructurallyCompared).candidateInternal()) }
override ASTNode candidate() { none() }
}
@@ -142,7 +142,7 @@ private class InternalCandidate extends StructurallyCompared {
class OperandComparedToSelf extends StructurallyCompared {
OperandComparedToSelf() { exists(Comparison comp | this = comp.getLeftOperand()) }
override Expr candidate() { result = getParent().(Comparison).getRightOperand() }
override Expr candidate() { result = this.getParent().(Comparison).getRightOperand() }
}
/**
@@ -152,7 +152,7 @@ class OperandComparedToSelf extends StructurallyCompared {
class SelfAssignment extends StructurallyCompared {
SelfAssignment() { exists(AssignExpr assgn | this = assgn.getLhs()) }
override Expr candidate() { result = getAssignment().getRhs() }
override Expr candidate() { result = this.getAssignment().getRhs() }
/**
* Gets the enclosing assignment.

View File

@@ -49,9 +49,9 @@ abstract class ImplicitConversionWithWhitelist extends ImplicitConversion {
abstract string getConversionTarget();
override string getAnImplicitConversionTarget(AbstractValue v) {
v = getAValue() and
not v.getType() = getAWhitelistedType() and
result = getConversionTarget()
v = this.getAValue() and
not v.getType() = this.getAWhitelistedType() and
result = this.getConversionTarget()
}
}
@@ -136,7 +136,7 @@ class NumericConversion extends ImplicitConversion {
}
override string getAnImplicitConversionTarget(AbstractValue v) {
v = getAValue() and
v = this.getAValue() and
not v.isCoercibleToNumber() and
result = "number"
}
@@ -149,9 +149,9 @@ abstract class NullOrUndefinedConversion extends ImplicitConversion {
abstract string getConversionTarget();
override string getAnImplicitConversionTarget(AbstractValue v) {
v = getAValue() and
v = this.getAValue() and
(v instanceof AbstractNull or v instanceof AbstractUndefined) and
result = getConversionTarget()
result = this.getConversionTarget()
}
}
@@ -163,9 +163,9 @@ class PlusConversion extends NullOrUndefinedConversion {
PlusConversion() { parent instanceof AddExpr or parent instanceof AssignAddExpr }
override string getConversionTarget() {
result = getDefiniteSiblingType()
result = this.getDefiniteSiblingType()
or
not exists(getDefiniteSiblingType()) and
not exists(this.getDefiniteSiblingType()) and
result = "number or string"
}
@@ -179,7 +179,8 @@ class PlusConversion extends NullOrUndefinedConversion {
* Gets the unique type of the sibling expression, if that type is `string` or `number`.
*/
private string getDefiniteSiblingType() {
result = unique(InferredType t | t = getSibling().flow().analyze().getAType()).getTypeofTag() and
result =
unique(InferredType t | t = this.getSibling().flow().analyze().getAType()).getTypeofTag() and
result = ["string", "number"]
}
}

View File

@@ -28,7 +28,7 @@ class IdentifierPart extends string {
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
exists(Identifier id, int start, Location l, int len |
occursIn(id, start, len) and l = id.getLocation()
this.occursIn(id, start, len) and l = id.getLocation()
|
filepath = l.getFile().getAbsolutePath() and
startline = l.getStartLine() and
@@ -70,7 +70,7 @@ class WrongIdentifierPart extends IdentifierPart {
string ppSuggestions() {
exists(string cat |
// first, concatenate with commas
cat = concat(getASuggestion(), ", ") and
cat = concat(this.getASuggestion(), ", ") and
// then, replace last comma with "or"
result = cat.regexpReplaceAll(", ([^,]++)$", " or $1")
)