-
Notifications
You must be signed in to change notification settings - Fork 91
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
Enforce same line bracket opens in Solidity #839
Comments
Let's start with utilizing our existing linter. Perhaps there is a rule which enforces line brackets to a particular format. If there is no such rule (or some other linter with such rule) then we could increase time estimate to |
Good point. I started looking into this as well, the existing linter should be able to enforce this. I will check and should have a solution today. |
I already found the root cause, we should use prettier-plugin-solidity in lint-staged settings. I will test and submit a pr soon. |
/start |
Tips:
|
I added the 'yarn format' to The full explanation is available at https://github.com/prettier-solidity/prettier-plugin-solidity/blob/main/STYLEGUIDE.md#function-declaration I will add a mention to the style guide in contracts README.md , pasting here below the content for full clarity. Function Declaration
function increment(uint x) public pure returns (uint) {
return x + 1;
}
function increment(uint x) public pure onlyowner returns (uint) {
return x + 1;
}
function kill() public onlyowner {
selfdestruct(owner);
}
function thisFunctionHasLotsOfArguments(
address a,
address b,
address c,
address d,
address e,
address f
)
public
{
doSomething();
}
function thisFunctionNameIsReallyLong(address x, address y, address z)
public
onlyowner
priced
returns (address)
{
doSomething();
}
function thisFunctionNameIsReallyLong(
address x,
address y,
address z,
)
public
onlyowner
priced
returns (address)
{
doSomething();
}
function thisFunctionNameIsReallyLong(
address a,
address b,
address c
)
public
returns (
address someAddressName,
uint256 LongArgument,
uint256 Argument
)
{
doSomething()
return (
veryLongReturnArg1,
veryLongReturnArg2,
veryLongReturnArg3
);
}
pragma solidity >=0.4.0 <0.7.0;
// Base contracts just to make this compile
contract B {
constructor(uint) public {
}
}
contract C {
constructor(uint, uint) public {
}
}
contract D {
constructor(uint) public {
}
}
contract A is B, C, D {
uint x;
constructor(uint param1, uint param2, uint param3, uint param4, uint param5)
B(param1)
C(param2, param3)
D(param4)
public
{
// do something with param5
x = param5;
}
} These guidelines for function declarations are intended to improve readability. Authors should use their best judgement as this guide does not try to cover all possible permutations for function declarations. Therefore, there are certain cases where the opening brace of a solidity function is formatted in the same line and some on the new line, depending on the rules above. |
workspaces Resolves: ubiquity#839
Pull request opened #840 |
the idea (my idea) is to enforce the tool to have the same pattern, this is a per best solidity practices, what do you think are the nuances on this due to long range functions with params? @gitcoindev unless rndqnuu has different in how he wants to format. best practice for solidity is function getPavlovcik() private {
}
struct PavlovcikInfo {
address info;
}
struct OpenPavlovick {
mapping(address => PavlovcikInfo) data;
} |
I guess we can use any approach towards the brackets formatting unless it is consistent across the whole project |
I checked a few big projects
They are also fine with mixed brackets formatting, see example here: https://github.com/Uniswap/v4-core/blob/main/src/test/MockHooks.sol vs https://github.com/Uniswap/v4-core/blob/main/src/test/MockContract.sol I would stick then to whatever prettier output formats, too. |
@molecula451 another point to use prettier output without changes is: https://prettier.io/docs/en/why-prettier And from the main website https://prettier.io/ Why?
And Ubiquity would use the same formatting tool as big code-bases, which makes it easier to onboard new partners / projects. |
"Hello, World!" |
Permit generation skipped because this issue has been closed by an external contributor. If you've enjoyed your experience in the DevPool, we'd appreciate your support. Follow Ubiquity on GitHub and star this repo. Your endorsement means the world to us and helps us grow!We are excited to announce that the DevPool and UbiquiBot are now available to partners! Our ideal collaborators are globally distributed crypto-native organizations, who actively work on open source on GitHub, and excel in research & development. If you can introduce us to the repository maintainers in these types of companies, we have a special bonus in store for you! |
Task Creator Rewardpavlovcik: [ CLAIM 26.7 WXDAI ] |
A custom
lint-staged
script would need to run to enforce this bracket style on commits. I was unable to find a tool out-of-the-box for this but it is possible that they exist.I looked into this and we would have to make a custom tool to enforce this with lint-staged I believe.
Originally posted by @pavlovcik in #832 (comment)
The text was updated successfully, but these errors were encountered: