vim-solidity icon indicating copy to clipboard operation
vim-solidity copied to clipboard

Better auto-indenting

Open mhluongo opened this issue 5 years ago • 3 comments

Inserting a new-line in the middle of an arg list or event indents incorrectly for default linting rules in ethlint.

Similarly, when this snippet below is auto-formatted with = in visual mode...

for (uint i = 0; i < numTokens; i++) {
    uint256 idealBalance = D1.mul(balances0[i]).div(D0);
    uint256 difference = idealBalance.difference(balances1[i]);
    fees[i] = _fee.mul(difference).div(FEE_DENOMINATOR);
    balances[i] = balances1[i].sub(fees[i].mul(_adminFee).div(
        FEE_DENOMINATOR));
    balances1[i] = balances1[i].sub(fees[i]);
}

the indent yields

for (uint i = 0; i < numTokens; i++) {
    uint256 idealBalance = D1.mul(balances0[i]).div(D0);
    uint256 difference = idealBalance.difference(balances1[i]);
    fees[i] = _fee.mul(difference).div(FEE_DENOMINATOR);
    balances[i] = balances1[i].sub(fees[i].mul(_adminFee).div(
        FEE_DENOMINATOR));
        balances1[i] = balances1[i].sub(fees[i]);
}

Not ideal.

mhluongo avatar Jul 09 '20 17:07 mhluongo

(Yet another unsolicited comment)

Have you tried prettier-solidity? It stills has some way to go, but it could really use the push of being used by a high profile project like tbtc. Formatting is a PITA (we removed styling rules in solhint for that reason), and I think it would be great if the community would move towards a unique formatting tool.

(This is my last bikeshedding, at least for today!)

fvictorio avatar Jul 13 '20 20:07 fvictorio

I'm planning on slapping prettier-solidity onto all Keep and tBTC code in the extremely near future for both CI and precommit formatting, independently of Matt's work here :) I've already poked at it and despite any imperfections, it's a big boon.

Shadowfiend avatar Jul 25 '20 00:07 Shadowfiend

@Shadowfiend glad to hear that! Feel free to open an issue for any imperfection you find, even bikeshedding is welcome :sweat_smile:

fvictorio avatar Jul 27 '20 13:07 fvictorio