Skip to content

forge fmt: Additional formatting features  #4116

Closed as not planned
Closed as not planned
@0xfarhaan

Description

@0xfarhaan

Component

Forge

Describe the feature you would like

Hey folks from Maple here, we would like to switch to using forge fmt, currently we're doing everything manually so this would save us alot of time and we're sure others could benefit too. Also happy to help with implementing!

Here are a list of options we would like in the formatter to make the switch:

  1. A new line at the top and bottom of top level declarations
interface interfaceName {

    code;
    code;
    code;

}

contract contractName1 {

    code;
    code;

}
  1. Ignore section headers (as they currently get reformatted)
/**************************************************************************************************************************************/
/*** Helpers                                                                                                                        ***/
/**************************************************************************************************************************************/
  1. For assertions of the same type, the parameters must be aligned so that the second set of parameters are left justified for each code block (this can be focussed around test helpers to start with)
assertEq(mockToken.balanceOf(address(treasury)), 0);    
assertEq(mockToken.balanceOf(address(mpl)),      100);  
assertEq(mockToken.balanceOf(address(holder1)),  0); 
assertEq(mockToken.balanceOf(address(holder2)),  0);    

assertEq(token.fundsBalance(),   60_000);
assertEq(token.pointsPerShare(), expectedPointsPerShare);
  1. Align the assignment operator for code blocks
function increaseCustodyAllowance(address custodian, uint256 amount) external override {
    uint256 oldAllowance      = custodyAllowance[msg.sender][custodian];
    uint256 newAllowance      = oldAllowance.add(amount);
    uint256 newTotalAllowance = totalCustodyAllowance[msg.sender].add(amount);

    PoolLib.increaseCustodyAllowanceChecks(custodian, amount, newTotalAllowance, balanceOf(msg.sender));

    custodyAllowance[msg.sender][custodian] = newAllowance;
    totalCustodyAllowance[msg.sender]       = newTotalAllowance;
}
  1. Add a space after the opening and before the closing bracket of a tuple
( , , uint256 foo, uint256 bar, , uint256 baz, , , ) = functionName();
( success, ) = functionName();
  1. Left justify align state variables by longest type for each code block
uint256 internal nextDelegateOriginationFee;
uint256 internal nextDelegateServiceFee;

uint256 internal start;

// Helper mapping to assert differences in balance
mapping(address => uint256) internal partialAssetBalances;

Asset        internal collateralAsset;
Asset        internal fundsAsset;
Globals      internal globals;
PoolDeployer internal deployer;

FeeManager        internal feeManager;
LoanManager       internal loanManager;
Pool              internal pool;
PoolDelegateCover internal poolCover;
PoolManager       internal poolManager;
WithdrawalManager internal withdrawalManager;
  1. Align imports by the furthest 'from' keyword in each code block
import { Address, TestUtils } from "../modules/contract-test-utils/contracts/test.sol";

import { MockERC20 as Asset } from "../modules/erc20/contracts/test/mocks/MockERC20.sol";

import { MapleGlobals as Globals } from "../modules/globals-v2/contracts/MapleGlobals.sol";
import { NonTransparentProxy }     from "../modules/globals-v2/modules/non-transparent-proxy/contracts/NonTransparentProxy.sol";

import { Liquidator }            from "../modules/liquidations/contracts/Liquidator.sol";
import { LiquidatorFactory }     from "../modules/liquidations/contracts/LiquidatorFactory.sol";
import { LiquidatorInitializer } from "../modules/liquidations/contracts/LiquidatorInitializer.sol";

import { MapleLoan as Loan }                       from "../modules/loan-v400/contracts/MapleLoan.sol";
import { MapleLoanFactory as LoanFactory }         from "../modules/loan-v400/contracts/MapleLoanFactory.sol";
import { MapleLoanFeeManager as FeeManager }       from "../modules/loan-v400/contracts/MapleLoanFeeManager.sol";
import { MapleLoanInitializer as LoanInitializer } from "../modules/loan-v400/contracts/MapleLoanInitializer.sol";

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions