Skip to content

Commit 8f705fc

Browse files
fulldecentnikola-matic
authored andcommitted
[Documentation] set error placement in contract, match example to prescription
Add example fix order
1 parent 0b4b104 commit 8f705fc

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

docs/style-guide.rst

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,14 +1058,40 @@ Inside each contract, library or interface, use the following order:
10581058
1. Type declarations
10591059
2. State variables
10601060
3. Events
1061-
4. Modifiers
1062-
5. Functions
1061+
4. Errors
1062+
5. Modifiers
1063+
6. Functions
10631064

10641065
.. note::
10651066

10661067
It might be clearer to declare types close to their use in events or state
10671068
variables.
10681069

1070+
Yes:
1071+
1072+
.. code-block:: solidity
1073+
1074+
// SPDX-License-Identifier: GPL-3.0
1075+
pragma solidity >=0.8.4 <0.9.0;
1076+
1077+
abstract contract Math {
1078+
error DivideByZero();
1079+
function divide(int256 numerator, int256 denominator) public virtual returns (uint256);
1080+
}
1081+
1082+
No:
1083+
1084+
.. code-block:: solidity
1085+
1086+
// SPDX-License-Identifier: GPL-3.0
1087+
pragma solidity >=0.8.4 <0.9.0;
1088+
1089+
abstract contract Math {
1090+
function divide(int256 numerator, int256 denominator) public virtual returns (uint256);
1091+
error DivideByZero();
1092+
}
1093+
1094+
10691095
******************
10701096
Naming Conventions
10711097
******************
@@ -1130,15 +1156,15 @@ Yes:
11301156
contract Owned {
11311157
address public owner;
11321158
1133-
constructor() {
1134-
owner = msg.sender;
1135-
}
1136-
11371159
modifier onlyOwner {
11381160
require(msg.sender == owner);
11391161
_;
11401162
}
11411163
1164+
constructor() {
1165+
owner = msg.sender;
1166+
}
1167+
11421168
function transferOwnership(address newOwner) public onlyOwner {
11431169
owner = newOwner;
11441170
}
@@ -1169,15 +1195,15 @@ No:
11691195
contract owned {
11701196
address public owner;
11711197
1172-
constructor() {
1173-
owner = msg.sender;
1174-
}
1175-
11761198
modifier onlyOwner {
11771199
require(msg.sender == owner);
11781200
_;
11791201
}
11801202
1203+
constructor() {
1204+
owner = msg.sender;
1205+
}
1206+
11811207
function transferOwnership(address newOwner) public onlyOwner {
11821208
owner = newOwner;
11831209
}

0 commit comments

Comments
 (0)