Skip to content

Commit

Permalink
Merge pull request #1470 from ardislu/dev
Browse files Browse the repository at this point in the history
Fix `naming-convention` to flag single letter `O` or `I` variable
  • Loading branch information
montyly authored Dec 20, 2022
2 parents ed8e585 + 82ab988 commit 696b42e
Show file tree
Hide file tree
Showing 9 changed files with 1,170 additions and 67 deletions.
29 changes: 14 additions & 15 deletions slither/detectors/naming_convention/naming_convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,21 @@ def _detect(self): # pylint: disable=too-many-branches,too-many-statements

for var in contract.state_variables_declared:
if self.should_avoid_name(var.name):
if not self.is_upper_case_with_underscores(var.name):
info = [
"Variable ",
var,
" used l, O, I, which should not be used\n",
]
info = [
"Variable ",
var,
" is single letter l, O, or I, which should not be used\n",
]

res = self.generate_result(info)
res.add(
var,
{
"target": "variable",
"convention": "l_O_I_should_not_be_used",
},
)
results.append(res)
res = self.generate_result(info)
res.add(
var,
{
"target": "variable",
"convention": "l_O_I_should_not_be_used",
},
)
results.append(res)

if var.is_constant is True:
# For ERC20 compatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ contract T {
uint constant M = 1;

uint l = 1;
uint O = 1;
uint I = 1;
}

contract ParameterNameEmptyString {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ contract T {
uint constant M = 1;

uint l = 1;
uint O = 1;
uint I = 1;
}

contract ParameterNameEmptyString {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ contract T {
uint constant M = 1;

uint l = 1;
uint O = 1;
uint I = 1;
}

contract ParameterNameEmptyString {
Expand Down

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/detectors/naming-convention/0.7.6/naming_convention.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ contract T {
uint constant M = 1;

uint l = 1;
uint O = 1;
uint I = 1;
}

contract ParameterNameEmptyString {
Expand Down

Large diffs are not rendered by default.

0 comments on commit 696b42e

Please sign in to comment.