Skip to content

Commit

Permalink
Merge pull request #499 from protofire/i486-enforce-underscore-nonext…
Browse files Browse the repository at this point in the history
…ernal

updated docs on  private-vars-leading-underscore rule
  • Loading branch information
dbale-altoros authored Sep 18, 2023
2 parents 2edf0d4 + 7ee36ba commit 354ae8b
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
56 changes: 55 additions & 1 deletion docs/rules/naming/private-vars-leading-underscore.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,63 @@ This rule accepts an array of options:
}
```

### Notes
- This rule skips external and public functions
- This rule skips external and public state variables
- See [here](https://docs.soliditylang.org/en/latest/style-guide.html#underscore-prefix-for-non-external-functions-and-variables) for further information

## Examples
This rule does not have examples.
### 👍 Examples of **correct** code for this rule

#### Internal function with correct naming

```solidity
function _thisIsInternal() internal {}
```

#### Private function with correct naming

```solidity
function _thisIsPrivate() private {}
```

#### Internal state variable with correct naming

```solidity
uint256 internal _thisIsInternalVariable;
```

#### Internal state variable with correct naming (no visibility is considered internal)

```solidity
uint256 _thisIsInternalVariable;
```

### 👎 Examples of **incorrect** code for this rule

#### Internal function with incorrect naming

```solidity
function thisIsInternal() internal {}
```

#### Private function with incorrect naming

```solidity
function thisIsPrivate() private {}
```

#### Internal state variable with incorrect naming

```solidity
uint256 internal thisIsInternalVariable;
```

#### Internal state variable with incorrect naming (no visibility is considered internal)

```solidity
uint256 thisIsInternalVariable;
```

## Version
This rule was introduced in [Solhint 3.0.0-rc.3](https://github.com/protofire/solhint/tree/v3.0.0-rc.3)
Expand Down
51 changes: 51 additions & 0 deletions lib/rules/naming/private-vars-leading-underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,57 @@ const meta = {
default: JSON.stringify(DEFAULT_OPTION),
},
],
examples: {
good: [
{
description: 'Internal function with correct naming',
code: 'function _thisIsInternal() internal {}',
},
{
description: 'Private function with correct naming',
code: 'function _thisIsPrivate() private {}',
},
{
description: 'Internal state variable with correct naming',
code: 'uint256 internal _thisIsInternalVariable;',
},
{
description:
'Internal state variable with correct naming (no visibility is considered internal)',
code: 'uint256 _thisIsInternalVariable;',
},
],
bad: [
{
description: 'Internal function with incorrect naming',
code: 'function thisIsInternal() internal {}',
},
{
description: 'Private function with incorrect naming',
code: 'function thisIsPrivate() private {}',
},
{
description: 'Internal state variable with incorrect naming',
code: 'uint256 internal thisIsInternalVariable;',
},
{
description:
'Internal state variable with incorrect naming (no visibility is considered internal)',
code: 'uint256 thisIsInternalVariable;',
},
],
},
notes: [
{
note: 'This rule skips external and public functions',
},
{
note: 'This rule skips external and public state variables',
},
{
note: 'See [here](https://docs.soliditylang.org/en/latest/style-guide.html#underscore-prefix-for-non-external-functions-and-variables) for further information',
},
],
},

isDefault: false,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solhint",
"version": "3.6.2",
"version": "3.6.3",
"description": "Solidity Code Linter",
"main": "lib/index.js",
"keywords": [
Expand Down

0 comments on commit 354ae8b

Please sign in to comment.