|
|
|
@ -47,9 +47,7 @@ class SimilarVarsDetection(AbstractDetector): |
|
|
|
|
Returns: |
|
|
|
|
bool: true if names are similar |
|
|
|
|
""" |
|
|
|
|
if len(seq1) != len(seq2): |
|
|
|
|
return False |
|
|
|
|
val = difflib.SequenceMatcher(a=seq1.lower(), b=seq2.lower()).ratio() |
|
|
|
|
val = difflib.SequenceMatcher(a=seq1, b=seq2).ratio() |
|
|
|
|
ret = val > 0.90 |
|
|
|
|
return ret |
|
|
|
|
|
|
|
|
@ -67,19 +65,21 @@ class SimilarVarsDetection(AbstractDetector): |
|
|
|
|
|
|
|
|
|
all_var = list(set(all_var + contract_var)) |
|
|
|
|
|
|
|
|
|
ret = [] |
|
|
|
|
ret = set() |
|
|
|
|
# pylint: disable=consider-using-enumerate |
|
|
|
|
for i in range(len(all_var)): |
|
|
|
|
v1 = all_var[i] |
|
|
|
|
_v1_name_lower = v1.name.lower() |
|
|
|
|
for j in range(i, len(all_var)): |
|
|
|
|
v2 = all_var[j] |
|
|
|
|
if _v1_name_lower != v2.name.lower(): |
|
|
|
|
if SimilarVarsDetection.similar(v1.name, v2.name): |
|
|
|
|
if (v2, v1) not in ret: |
|
|
|
|
ret.append((v1, v2)) |
|
|
|
|
if len(v1.name) != len(v2.name): |
|
|
|
|
continue |
|
|
|
|
_v2_name_lower = v2.name.lower() |
|
|
|
|
if _v1_name_lower != _v2_name_lower: |
|
|
|
|
if SimilarVarsDetection.similar(_v1_name_lower, _v2_name_lower): |
|
|
|
|
ret.add((v1, v2)) |
|
|
|
|
|
|
|
|
|
return set(ret) |
|
|
|
|
return ret |
|
|
|
|
|
|
|
|
|
def _detect(self) -> List[Output]: |
|
|
|
|
"""Detect similar variables name |
|
|
|
|