Skip to content

Commit

Permalink
Update style guide (#12041)
Browse files Browse the repository at this point in the history
  • Loading branch information
RensR authored Feb 15, 2024
1 parent 4ad5eb9 commit f8cdac1
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions contracts/STYLE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,10 @@ Here are some examples of what this should look like:

```solidity
contract AccessControlledFoo is Foo {
// solhint-disable-next-line chainlink-solidity/all-caps-constant-storage-variables
string public constant override typeAndVersion = "AccessControlledFoo 1.0.0";
}
contract OffchainAggregator is ITypeAndVersion {
// solhint-disable-next-line chainlink-solidity/all-caps-constant-storage-variables
string public constant override typeAndVersion = "OffchainAggregator 1.0.0";
function getData() public returns(uint256) {
Expand All @@ -256,8 +254,6 @@ contract OffchainAggregator is ITypeAndVersion {
contract SuperDuperAggregator is ITypeAndVersion {
/// This is a new contract that has not been released yet, so we
/// add a `-dev` suffix to the typeAndVersion.
// solhint-disable-next-line chainlink-solidity/all-caps-constant-storage-variables
string public constant override typeAndVersion = "SuperDuperAggregator 1.1.0-dev";
function getData() public returns(uint256) {
Expand Down Expand Up @@ -388,4 +384,27 @@ rule: `custom-errors`

Interfaces should be named `IFoo` instead of `FooInterface`. This follows the patterns of popular [libraries like OpenZeppelin’s](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol#L9).

rule: `tbd`
rule: `tbd`

## Structs

Structs should be constructed with named arguments. This prevents accidental assignment to the wrong field and makes the code more readable.

```solidity
// Good
function setConfig(uint64 _foo, uint64 _bar, uint64 _baz) external {
config = Config({
foo: _foo,
bar: _bar,
baz: _baz
});
}
// Bad
function setConfig(uint64 _foo, uint64 _bar, uint64 _baz) external {
config = Config(_foo, _bar, _baz);
}
```

rule: `tbd`

0 comments on commit f8cdac1

Please sign in to comment.