Closed 0x4007 closed 12 months ago
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 < 1 Day
to create our own custom solution.
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
< 1 Day
to create our own custom solution.
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
Deadline | Mon, 20 Nov 2023 13:37:26 UTC |
Registered Wallet | 0x7e92476D69Ff1377a8b45176b1829C4A5566653a |
/wallet 0x0000...0000
if you want to update your registered payment wallet address @user.I added the 'yarn format' to packages/contracts
, made sure prettier-plugin-solidity is explicitly used and all in all the current formatting of development
branch contracts matches Prettier
way of formatting.
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.
[x] For short function declarations, it is recommended for the opening brace of the function body to be kept on the same line as the function declaration.
The closing brace should be at the same indentation level as the function declaration.
The opening brace should be preceded by a single space.
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.
Pull request opened https://github.com/ubiquity/ubiquity-dollar/pull/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 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.
getPavlovcik()
"Hello, World!"
Permit generation skipped because this issue has been closed by an external contributor.
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 https://github.com/ubiquity/ubiquity-dollar/issues/832#issuecomment-1818047062