Variables that are not in contract state should start with underscore. Conversely, variables that can cause an SLOAD/SSTORE should NOT start with an underscore. This makes it evident which operations cause expensive storage access when hunting for gas optimizations
This rule accepts an array of options:
Index | Description | Default Value |
---|---|---|
0 | Rule severity. Must be one of “error”, “warn”, “off”. | warn |
{
"rules": {
"non-state-vars-leading-underscore": ["warn"]
}
}
pragma solidity 0.4.4;
contract A {
uint256 public foo;
}
pragma solidity 0.4.4;
contract A {
uint256 immutable public _FOO;
}
pragma solidity 0.4.4;
contract A {
function foo() public { uint _myVar; }
}
pragma solidity 0.4.4;
contract A {
function foo( uint256 _foo ) public {}
}
pragma solidity 0.4.4;
contract A {
uint256 public _foo;
}
pragma solidity 0.4.4;
contract A {
function foo() public { uint myVar; }
}
pragma solidity 0.4.4;
contract A {
function foo( uint256 foo ) public {}
}
This rule was introduced in Solhint 4.0.0-rc01