foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.19k stars 1.7k forks source link

feat(fmt): allow `line_length` to be a hard requirement #4450

Open PaulRBerg opened 1 year ago

PaulRBerg commented 1 year ago

Component

Forge

Describe the feature you would like

As discussed here with @mds1, it would be helpful to be able to make line_length a hard requirement. At the moment, forge fmt will leave untouched those statements that exceed the line length by 1 or 2 characters. For instance:

error SablierV2Pro__NetDepositAmountNotEqualToSegmentAmountsSum(uint128 netDepositAmount, uint128 segmentAmountsSum);

This line has 121 lines, but I have set the line_length to 1.

This is problematic because other Solidity linting tools (e.g. Solhint) consider the max-line-length rule to be a hard requirement.

CodeSandwich commented 1 year ago

Another example, with function calls:

contract NotSoPretty {
    function foo() public pure {
        uint256 baz;
        // These lines have length 121
        baz = bar(1111111111111111111111111111111111111111111111111111111111, 11111111111111111111111111111111111111111);
        baz =
            bar(111111111111111111111111111111111111111111111111111111111111111, 11111111111111111111111111111111111111);
        bar(1111111111111111111111111111111111111111111111111111, 11111111111111111111111111111111111111111111111111111);

        // Extend the lines to 122 and they finally break
        baz =
            bar(1111111111111111111111111111111111111111111111111111111111, 111111111111111111111111111111111111111110);
        baz = bar(
            111111111111111111111111111111111111111111111111111111111111111, 111111111111111111111111111111111111110
        );
        bar(
            1111111111111111111111111111111111111111111111111111, 111111111111111111111111111111111111111111111111111110
        );
    }

    function bar(uint256, uint256) private pure returns (uint256) {
        return 0;
    }
}
ashishbinu commented 1 year ago

I have faced this same issue with lines being 121 characters long and forge fmt doesn't format it to 120 lines. But if I change the line_length = 119 it doesn work and change it to under 119 characters. It seems highly unpredictable