Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Rule: Named Struct Arguments #12

Open
justinkaseman opened this issue Feb 15, 2024 · 0 comments
Open

New Rule: Named Struct Arguments #12

justinkaseman opened this issue Feb 15, 2024 · 0 comments

Comments

@justinkaseman
Copy link

Description

Add a solhint rule to enforce the following recommendation from the Chainlink contracts style guide:

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

// 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);
}

https://github.com/smartcontractkit/chainlink/blob/3a74dc13b2d42316803b26b2254caa12f7beccb4/contracts/STYLE_GUIDE.md?plain=1#L389

Steps

  1. Make a solhint rule and open a PR against this repository's master branch
  2. Once merged, open a PR to the Chainlink repository that updates the STYLE_GUIDE.md to reference the new rule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant