solhint-community

private-vars-leading-underscore

Category Badge Default Severity Badge warn

Description

Private and internal names must start with a single underscore.

Options

This rule accepts an array of options:

Index Description Default Value
0 Rule severity. Must be one of “error”, “warn”, “off”. warn
1 A JSON object with a single property “strict” specifying if the rule should apply to non state variables. Default: { strict: false }. {“strict”:false}

Example Config

{
  "rules": {
    "private-vars-leading-underscore": ["warn",{"strict":false}]
  }
}

Notes

Examples

👍 Examples of correct code for this rule

Internal function starting with an underscore

function _thisIsInternal() internal {}

Private function starting with an underscore

function _thisIsPrivate() private {}

Internal state variable starting with an underscore

uint256 internal _thisIsInternalVariable;

with {strict: false}, memory variables starting with an underscore is not considered an error

function foo(uint256 _bar) public {}

Internal state variable starting with an underscore (no visibility is considered internal)

uint256 _thisIsInternalVariable;

👎 Examples of incorrect code for this rule

with {strict: true}, memory variables starting with an underscore are considered an error

function foo(uint256 _bar) public {}

public/external function name starts with an underscore

function _foo() public {}

Internal function does not start with an underscore

function thisIsInternal() internal {}

Private function does not start with an underscore

function thisIsPrivate() private {}

Internal state variable does not start with an underscore

uint256 internal thisIsInternalVariable;

Internal state variable does not start with an underscore(no visibility is considered internal)

uint256 thisIsInternalVariable;

Version

This rule was introduced in Solhint 3.0.0-rc.3

Resources