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

Forge formatter fails to format multi-line function header #9563

Closed
2 tasks done
emilesean opened this issue Dec 16, 2024 · 2 comments
Closed
2 tasks done

Forge formatter fails to format multi-line function header #9563

emilesean opened this issue Dec 16, 2024 · 2 comments
Labels
T-bug Type: bug T-needs-triage Type: this issue needs to be labelled

Comments

@emilesean
Copy link

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (206dab2 2024-12-16T00:25:12.607328550Z)

What command(s) is the bug in?

forge fmt

Operating System

Linux

Describe the bug

Forge formatter fails to format mulit-line function header

Steps to reproduce

  1. Create a foundry project
forge init random
cd random
  1. Create a IERC20.sol file with the following content.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

interface IERC20 {
    function totalSupply() external view returns (uint256);

    function balanceOf(address account) external view returns (uint256);

    function transfer(address recipient, uint256 amount) external returns (bool);

    function allowance(address owner, address spender) external view returns (uint256);

    function approve(address spender, uint256 amount) external returns (bool);

    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}
  1. Configure formatter add the following into foundry.toml file
[fmt]
single_line_statement_blocks = "multi"
multiline_func_header = 'params_first'
  1. format the contents
forge fmt ./IERC20.sol
  1. Output
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

interface IERC20 {
    function totalSupply() external view returns (uint256);

    function balanceOf(
        address account
    ) external view returns (uint256);

    function transfer(address recipient, uint256 amount) external returns (bool);

    function allowance(address owner, address spender) external view returns (uint256);

    function approve(address spender, uint256 amount) external returns (bool);

    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}
  1. Expected Output
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

interface IERC20 {
    function totalSupply() external view returns (uint256);

    function balanceOf(address account) external view returns (uint256);

    function transfer(
        address recipient,
        uint256 amount
    ) external returns (bool);

    function allowance(
        address owner,
        address spender
    ) external view returns (uint256);

    function approve(address spender, uint256 amount) external returns (bool);

    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
}
@emilesean emilesean added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Dec 16, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Dec 16, 2024
@grandizzy
Copy link
Collaborator

@emilesean per docs

The multiline_func_header configuration option in Foundry controls how function headers (the line containing the function name, parameters, return values etc.) are formatted when they exceed the max line length.

your sample doesn't exceed max line length (default to 120) hence no formatting, if you set line_length = 80 for example, they'll be formatted. Please reopen if still an issue, thank you!

@grandizzy grandizzy closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Dec 16, 2024
@clouds56
Copy link

clouds56 commented Dec 19, 2024

Now params_first would break function header into multiline with single parameter not matter its line width,
e.g. it would fmt

  function transfer(address to, uint value) external;
  function balanceOf(address account) external;

to

  function transfer(address to, uint256 value) external;
  function balanceOf(
    address account
  ) external;

Even if balanceOf is shorter than transfer.

Update

Use params_first_multi instead of params_first. See also #8762

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug T-needs-triage Type: this issue needs to be labelled
Projects
Status: Done
Development

No branches or pull requests

3 participants