diff --git a/slither/detectors/naming_convention/naming_convention.py b/slither/detectors/naming_convention/naming_convention.py index 5e81f003c4..94fd2e8f91 100644 --- a/slither/detectors/naming_convention/naming_convention.py +++ b/slither/detectors/naming_convention/naming_convention.py @@ -139,7 +139,8 @@ def _detect(self): # pylint: disable=too-many-branches,too-many-statements # For ERC20 compatibility if var.name in ["symbol", "name", "decimals"]: continue - + if var.visibility == "public": + continue if not self.is_upper_case_with_underscores(var.name): info = [ "Constant ", diff --git a/tests/detectors/naming-convention/0.4.25/no_warning_for_public_constants.sol b/tests/detectors/naming-convention/0.4.25/no_warning_for_public_constants.sol new file mode 100644 index 0000000000..0c1da4c26c --- /dev/null +++ b/tests/detectors/naming-convention/0.4.25/no_warning_for_public_constants.sol @@ -0,0 +1,4 @@ +contract A +{ + uint256 public constant myVal = 0; +} \ No newline at end of file diff --git a/tests/detectors/naming-convention/0.4.25/no_warning_for_public_constants.sol.0.4.25.NamingConvention.json b/tests/detectors/naming-convention/0.4.25/no_warning_for_public_constants.sol.0.4.25.NamingConvention.json new file mode 100644 index 0000000000..5825bcacc6 --- /dev/null +++ b/tests/detectors/naming-convention/0.4.25/no_warning_for_public_constants.sol.0.4.25.NamingConvention.json @@ -0,0 +1,3 @@ +[ + [] +] \ No newline at end of file diff --git a/tests/detectors/naming-convention/0.5.16/no_warning_for_public_constants.sol b/tests/detectors/naming-convention/0.5.16/no_warning_for_public_constants.sol new file mode 100644 index 0000000000..0c1da4c26c --- /dev/null +++ b/tests/detectors/naming-convention/0.5.16/no_warning_for_public_constants.sol @@ -0,0 +1,4 @@ +contract A +{ + uint256 public constant myVal = 0; +} \ No newline at end of file diff --git a/tests/detectors/naming-convention/0.5.16/no_warning_for_public_constants.sol.0.5.16.NamingConvention.json b/tests/detectors/naming-convention/0.5.16/no_warning_for_public_constants.sol.0.5.16.NamingConvention.json new file mode 100644 index 0000000000..5825bcacc6 --- /dev/null +++ b/tests/detectors/naming-convention/0.5.16/no_warning_for_public_constants.sol.0.5.16.NamingConvention.json @@ -0,0 +1,3 @@ +[ + [] +] \ No newline at end of file diff --git a/tests/detectors/naming-convention/0.6.11/no_warning_for_public_constants.sol b/tests/detectors/naming-convention/0.6.11/no_warning_for_public_constants.sol new file mode 100644 index 0000000000..0c1da4c26c --- /dev/null +++ b/tests/detectors/naming-convention/0.6.11/no_warning_for_public_constants.sol @@ -0,0 +1,4 @@ +contract A +{ + uint256 public constant myVal = 0; +} \ No newline at end of file diff --git a/tests/detectors/naming-convention/0.6.11/no_warning_for_public_constants.sol.0.6.11.NamingConvention.json b/tests/detectors/naming-convention/0.6.11/no_warning_for_public_constants.sol.0.6.11.NamingConvention.json new file mode 100644 index 0000000000..5825bcacc6 --- /dev/null +++ b/tests/detectors/naming-convention/0.6.11/no_warning_for_public_constants.sol.0.6.11.NamingConvention.json @@ -0,0 +1,3 @@ +[ + [] +] \ No newline at end of file diff --git a/tests/detectors/naming-convention/0.7.6/no_warning_for_public_constants.sol b/tests/detectors/naming-convention/0.7.6/no_warning_for_public_constants.sol new file mode 100644 index 0000000000..e5371cbe32 --- /dev/null +++ b/tests/detectors/naming-convention/0.7.6/no_warning_for_public_constants.sol @@ -0,0 +1,4 @@ +contract A +{ + uint256 public constant myVal = 0; +} diff --git a/tests/detectors/naming-convention/0.7.6/no_warning_for_public_constants.sol.0.7.6.NamingConvention.json b/tests/detectors/naming-convention/0.7.6/no_warning_for_public_constants.sol.0.7.6.NamingConvention.json new file mode 100644 index 0000000000..5825bcacc6 --- /dev/null +++ b/tests/detectors/naming-convention/0.7.6/no_warning_for_public_constants.sol.0.7.6.NamingConvention.json @@ -0,0 +1,3 @@ +[ + [] +] \ No newline at end of file diff --git a/tests/test_detectors.py b/tests/test_detectors.py index 994f87aac4..860b281b35 100644 --- a/tests/test_detectors.py +++ b/tests/test_detectors.py @@ -609,6 +609,26 @@ def id_test(test_item: Test): "naming_convention.sol", "0.7.6", ), + Test( + all_detectors.NamingConvention, + "no_warning_for_public_constants.sol", + "0.4.25", + ), + Test( + all_detectors.NamingConvention, + "no_warning_for_public_constants.sol", + "0.5.16", + ), + Test( + all_detectors.NamingConvention, + "no_warning_for_public_constants.sol", + "0.6.11", + ), + Test( + all_detectors.NamingConvention, + "no_warning_for_public_constants.sol", + "0.7.6", + ), Test( all_detectors.ControlledDelegateCall, "controlled_delegatecall.sol",