Merge pull request #6874 from ethereum/docs-style-fix-style

[DOCS] Bring code examples for Style Guide inline with style guide
This commit is contained in:
Chris Chinchilla 2019-06-06 11:23:15 +02:00 committed by GitHub
commit fc35c139ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -757,20 +757,26 @@ No::
pragma solidity >=0.4.0 <0.7.0; pragma solidity >=0.4.0 <0.7.0;
// Base contracts just to make this compile // Base contracts just to make this compile
contract B { contract B {
constructor(uint) public { constructor(uint) public {
} }
} }
contract C { contract C {
constructor(uint, uint) public { constructor(uint, uint) public {
} }
} }
contract D { contract D {
constructor(uint) public { constructor(uint) public {
} }
} }
contract A is B, C, D { contract A is B, C, D {
uint x; uint x;
@ -778,12 +784,12 @@ No::
B(param1) B(param1)
C(param2, param3) C(param2, param3)
D(param4) D(param4)
public public {
{
x = param5; x = param5;
} }
} }
contract X is B, C, D { contract X is B, C, D {
uint x; uint x;
@ -792,10 +798,11 @@ No::
C(param2, param3) C(param2, param3)
D(param4) D(param4)
public { public {
x = param5; x = param5;
} }
} }
When declaring short functions with a single statement, it is permissible to do it on a single line. When declaring short functions with a single statement, it is permissible to do it on a single line.
Permissible:: Permissible::
@ -973,27 +980,32 @@ Yes::
pragma solidity >=0.4.0 <0.7.0; pragma solidity >=0.4.0 <0.7.0;
// Owned.sol // Owned.sol
contract Owned { contract Owned {
address public owner; address public owner;
constructor() public { constructor() public {
owner = msg.sender; owner = msg.sender;
} }
modifier onlyOwner { modifier onlyOwner {
require(msg.sender == owner); require(msg.sender == owner);
_; _;
} }
function transferOwnership(address newOwner) public onlyOwner { function transferOwnership(address newOwner) public onlyOwner {
owner = newOwner; owner = newOwner;
} }
} }
// Congress.sol and in ``Congress.sol``::
pragma solidity >=0.4.0 <0.7.0;
import "./Owned.sol"; import "./Owned.sol";
contract Congress is Owned, TokenRecipient { contract Congress is Owned, TokenRecipient {
//... //...
} }
@ -1002,32 +1014,34 @@ No::
pragma solidity >=0.4.0 <0.7.0; pragma solidity >=0.4.0 <0.7.0;
// owned.sol // owned.sol
contract owned { contract owned {
address public owner; address public owner;
constructor() public { constructor() public {
owner = msg.sender; owner = msg.sender;
} }
modifier onlyOwner { modifier onlyOwner {
require(msg.sender == owner); require(msg.sender == owner);
_; _;
} }
function transferOwnership(address newOwner) public onlyOwner { function transferOwnership(address newOwner) public onlyOwner {
owner = newOwner; owner = newOwner;
} }
} }
// Congress.sol and in ``Congress.sol``::
import "./owned.sol"; import "./owned.sol";
contract Congress is owned, tokenRecipient { contract Congress is owned, tokenRecipient {
//... //...
} }
Struct Names Struct Names
========================== ==========================
@ -1104,6 +1118,7 @@ added looks like the one below::
pragma solidity >=0.4.0 <0.7.0; pragma solidity >=0.4.0 <0.7.0;
/// @author The Solidity Team /// @author The Solidity Team
/// @title A simple storage example /// @title A simple storage example
contract SimpleStorage { contract SimpleStorage {
@ -1126,4 +1141,4 @@ added looks like the one below::
It is recommended that Solidity contracts are fully annontated using `NatSpec <natspec>`_ for all public interfaces (everything in the ABI). It is recommended that Solidity contracts are fully annontated using `NatSpec <natspec>`_ for all public interfaces (everything in the ABI).
Please see the section about `NatSpec <natspec>`_ for a detailed explanation. Please see the section about `NatSpec <natspec>`_ for a detailed explanation.