Docs style guide

This commit is contained in:
Leonardo Alt 2019-12-12 20:12:42 +01:00
parent df076e072d
commit 3198f55d24
2 changed files with 26 additions and 21 deletions

View File

@ -297,7 +297,7 @@ of the variable:
contract A contract A
{ {
function f() external virtual pure returns(uint) { return 5; } function f() external pure virtual returns(uint) { return 5; }
} }
contract B is A contract B is A

View File

@ -98,11 +98,11 @@ Yes::
contract B is A { contract B is A {
function spam() public override pure { function spam() public pure override {
// ... // ...
} }
function ham() public override pure { function ham() public pure override {
// ... // ...
} }
} }
@ -111,11 +111,17 @@ No::
pragma solidity >=0.4.0 <0.7.0; pragma solidity >=0.4.0 <0.7.0;
contract A { abstract contract A {
function spam() public pure { function spam() virtual pure public;
function ham() public virtual pure;
}
contract B is A {
function spam() public pure override {
// ... // ...
} }
function ham() public pure { function ham() public pure override {
// ... // ...
} }
} }
@ -564,31 +570,30 @@ No::
function increment(uint x) public pure returns (uint) { function increment(uint x) public pure returns (uint) {
return x + 1;} return x + 1;}
You should explicitly label the visibility of all functions, including constructors. The modifier order for a function should be:
1. Visibility
2. Mutability
3. Virtual
4. Override
5. Custom modifiers
Yes:: Yes::
function explicitlyPublic(uint val) public { function balance(uint from) public view override returns (uint) {
doSomething(); return balanceOf[from];
} }
No::
function implicitlyPublic(uint val) {
doSomething();
}
The visibility modifier for a function should come before any custom
modifiers.
Yes::
function kill() public onlyowner { function kill() public onlyowner {
selfdestruct(owner); selfdestruct(owner);
} }
No:: No::
function balance(uint from) public override view returns (uint) {
return balanceOf[from];
}
function kill() onlyowner public { function kill() onlyowner public {
selfdestruct(owner); selfdestruct(owner);
} }