Skip to content

Commit 354ae8b

Browse files
Merge pull request #499 from protofire/i486-enforce-underscore-nonexternal
updated docs on private-vars-leading-underscore rule
2 parents 2edf0d4 + 7ee36ba commit 354ae8b

File tree

3 files changed

+107
-2
lines changed

3 files changed

+107
-2
lines changed

docs/rules/naming/private-vars-leading-underscore.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,63 @@ This rule accepts an array of options:
2929
}
3030
```
3131

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

3337
## Examples
34-
This rule does not have examples.
38+
### 👍 Examples of **correct** code for this rule
39+
40+
#### Internal function with correct naming
41+
42+
```solidity
43+
function _thisIsInternal() internal {}
44+
```
45+
46+
#### Private function with correct naming
47+
48+
```solidity
49+
function _thisIsPrivate() private {}
50+
```
51+
52+
#### Internal state variable with correct naming
53+
54+
```solidity
55+
uint256 internal _thisIsInternalVariable;
56+
```
57+
58+
#### Internal state variable with correct naming (no visibility is considered internal)
59+
60+
```solidity
61+
uint256 _thisIsInternalVariable;
62+
```
63+
64+
### 👎 Examples of **incorrect** code for this rule
65+
66+
#### Internal function with incorrect naming
67+
68+
```solidity
69+
function thisIsInternal() internal {}
70+
```
71+
72+
#### Private function with incorrect naming
73+
74+
```solidity
75+
function thisIsPrivate() private {}
76+
```
77+
78+
#### Internal state variable with incorrect naming
79+
80+
```solidity
81+
uint256 internal thisIsInternalVariable;
82+
```
83+
84+
#### Internal state variable with incorrect naming (no visibility is considered internal)
85+
86+
```solidity
87+
uint256 thisIsInternalVariable;
88+
```
3589

3690
## Version
3791
This rule was introduced in [Solhint 3.0.0-rc.3](https://github.com/protofire/solhint/tree/v3.0.0-rc.3)

lib/rules/naming/private-vars-leading-underscore.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,57 @@ const meta = {
2424
default: JSON.stringify(DEFAULT_OPTION),
2525
},
2626
],
27+
examples: {
28+
good: [
29+
{
30+
description: 'Internal function with correct naming',
31+
code: 'function _thisIsInternal() internal {}',
32+
},
33+
{
34+
description: 'Private function with correct naming',
35+
code: 'function _thisIsPrivate() private {}',
36+
},
37+
{
38+
description: 'Internal state variable with correct naming',
39+
code: 'uint256 internal _thisIsInternalVariable;',
40+
},
41+
{
42+
description:
43+
'Internal state variable with correct naming (no visibility is considered internal)',
44+
code: 'uint256 _thisIsInternalVariable;',
45+
},
46+
],
47+
bad: [
48+
{
49+
description: 'Internal function with incorrect naming',
50+
code: 'function thisIsInternal() internal {}',
51+
},
52+
{
53+
description: 'Private function with incorrect naming',
54+
code: 'function thisIsPrivate() private {}',
55+
},
56+
{
57+
description: 'Internal state variable with incorrect naming',
58+
code: 'uint256 internal thisIsInternalVariable;',
59+
},
60+
{
61+
description:
62+
'Internal state variable with incorrect naming (no visibility is considered internal)',
63+
code: 'uint256 thisIsInternalVariable;',
64+
},
65+
],
66+
},
67+
notes: [
68+
{
69+
note: 'This rule skips external and public functions',
70+
},
71+
{
72+
note: 'This rule skips external and public state variables',
73+
},
74+
{
75+
note: 'See [here](https://docs.soliditylang.org/en/latest/style-guide.html#underscore-prefix-for-non-external-functions-and-variables) for further information',
76+
},
77+
],
2778
},
2879

2980
isDefault: false,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solhint",
3-
"version": "3.6.2",
3+
"version": "3.6.3",
44
"description": "Solidity Code Linter",
55
"main": "lib/index.js",
66
"keywords": [

0 commit comments

Comments
 (0)