Formatter
Configuration related to the behavior of the Forge formatter. Each of these keys live under the [fmt] section.
line_length
- Type: number
- Default: 120
- Environment:
FOUNDRY_FMT_LINE_LENGTHorDAPP_FMT_LINE_LENGTH
Maximum line length where formatter will try to wrap the line.
tab_width
- Type: number
- Default: 4
- Environment:
FOUNDRY_FMT_TAB_WIDTHorDAPP_FMT_TAB_WIDTH
Number of spaces per indentation level. Ignored if style is set to "tab".
style
- Type: string
- Default:
space - Environment:
FOUNDRY_FMT_STYLEorDAPP_FMT_STYLE
Indentation style. Valid values are:
space(default): Use spaces for indentationtab: Use tabs for indentation
bracket_spacing
- Type: bool
- Default: false
- Environment:
FOUNDRY_FMT_BRACKET_SPACINGorDAPP_FMT_BRACKET_SPACING
Whether or not to print spaces between brackets.
int_types
- Type: string
- Default:
long - Environment:
FOUNDRY_FMT_INT_TYPESorDAPP_FMT_INT_TYPES
Style of uint/int256 types. Valid values are:
long(default): Use the explicituint256orint256short: Use the implicituintorintpreserve: Use the type defined in the source code
multiline_func_header
- Type: string
- Default:
attributes_first - Environment:
FOUNDRY_FMT_MULTILINE_FUNC_HEADERorDAPP_FMT_MULTILINE_FUNC_HEADER
Style of multiline function header in case it doesn't fit in one line. Valid values are:
attributes_first(default): Write function attributes multiline firstparams_always: Always write function parameters multilineparams_first_multi: Write function parameters multiline first when there is more than one paramall: If function params or attrs are multiline, multiline everythingall_params: Same asallbut writes function params multiline even when there is a single param
For example, with params_always:
function myFunction(
uint256 param1,
uint256 param2,
uint256 param3
) public returns (uint256) {
// ...
}And with all:
function myFunction(
uint256 param1,
uint256 param2,
uint256 param3
)
public
returns (uint256)
{
// ...
}quote_style
- Type: string
- Default:
double - Environment:
FOUNDRY_FMT_QUOTE_STYLEorDAPP_FMT_QUOTE_STYLE
Defines the quotation mark style. Valid values are:
double(default): Use double quotes where possible (")single: Use single quotes where possible (')preserve: Use quotation mark defined in the source code
number_underscore
- Type: string
- Default:
preserve - Environment:
FOUNDRY_FMT_NUMBER_UNDERSCOREorDAPP_FMT_NUMBER_UNDERSCORE
Style of underscores in number literals. Valid values are:
preserve(default): Use the underscores defined in the source codethousands: Add an underscore every thousand, if greater than 9999. i.e.1000is formatted as1000and10000as10_000remove: Remove all underscores
hex_underscore
- Type: string
- Default:
remove - Environment:
FOUNDRY_FMT_HEX_UNDERSCOREorDAPP_FMT_HEX_UNDERSCORE
Style of underscores in hex literals. Valid values are:
preserve: Use the underscores defined in the source coderemove(default): Remove all underscoresbytes: Add underscore as separator between byte boundaries. i.e.hex"deadbeef"is formatted ashex"de_ad_be_ef"
single_line_statement_blocks
- Type: string
- Default:
preserve - Environment:
FOUNDRY_FMT_SINGLE_LINE_STATEMENT_BLOCKSorDAPP_FMT_SINGLE_LINE_STATEMENT_BLOCKS
Style of single line blocks in statements. Valid values are:
preserve(default): Keep the existing single/multi line formatting of statement blockssingle: Statement blocks will be formatted to a single line if possiblemulti: Statement blocks will always be formatted to multiple lines
For example, with single:
if (true) { return true; }With multi:
if (true) {
return true;
}override_spacing
- Type: bool
- Default: false
- Environment:
FOUNDRY_FMT_OVERRIDE_SPACINGorDAPP_FMT_OVERRIDE_SPACING
Whether to print a space in state variable, function and modifier override attribute.
When enabled:
function foo() override (Parent) public { }When disabled:
function foo() override(Parent) public { }wrap_comments
- Type: bool
- Default: false
- Environment:
FOUNDRY_FMT_WRAP_COMMENTSorDAPP_FMT_WRAP_COMMENTS
Whether or not to wrap comments on line_length reached.
docs_style
- Type: string
- Default:
preserve - Environment:
FOUNDRY_FMT_DOCS_STYLEorDAPP_FMT_DOCS_STYLE
Style of doc comments. Valid values are:
preserve(default): Preserve the source code styleline: Use single-line style (///)block: Use block style (/** ... */)
ignore
- Type: array of strings (patterns)
- Default:
[] - Environment:
FOUNDRY_FMT_IGNOREorDAPP_FMT_IGNORE
List of files to ignore when formatting. This is a comma separated list of glob patterns.
[fmt]
ignore = ["src/vendor/**/*.sol", "lib/**/*.sol"]contract_new_lines
- Type: bool
- Default: false
- Environment:
FOUNDRY_FMT_CONTRACT_NEW_LINESorDAPP_FMT_CONTRACT_NEW_LINES
Whether to add new lines before and after contract declarations.
When enabled:
// imports...
contract MyContract {
// ...
}
contract AnotherContract {
// ...
}sort_imports
- Type: bool
- Default: false
- Environment:
FOUNDRY_FMT_SORT_IMPORTSorDAPP_FMT_SORT_IMPORTS
Whether to sort import statements alphabetically within their import groups. Groups are separated by blank lines.
namespace_import_style
- Type: string
- Default:
prefer_plain - Environment:
FOUNDRY_FMT_NAMESPACE_IMPORT_STYLEorDAPP_FMT_NAMESPACE_IMPORT_STYLE
Choose between import styles. Valid values are:
prefer_plain(default): Preferimport "source" as name;prefer_glob: Preferimport * as name from "source";preserve: Preserve the original style
pow_no_space
- Type: bool
- Default: false
- Environment:
FOUNDRY_FMT_POW_NO_SPACEorDAPP_FMT_POW_NO_SPACE
Whether to suppress spaces around the power operator (**).
When enabled:
uint256 result = base**exponent;When disabled (default):
uint256 result = base ** exponent;prefer_compact
- Type: string
- Default:
all - Environment:
FOUNDRY_FMT_PREFER_COMPACTorDAPP_FMT_PREFER_COMPACT
Style that determines if a broken list should keep its elements together on their own line, before breaking individually. Valid values are:
all(default): All elements are preferred compactnone: All elements are preferred consistentcalls: Calls are preferred compact; events and errors break consistentlyevents: Events are preferred compact; calls and errors break consistentlyerrors: Errors are preferred compact; calls and events break consistentlyevents_errors: Events and errors are preferred compact; calls break consistently
single_line_imports
- Type: bool
- Default: false
- Environment:
FOUNDRY_FMT_SINGLE_LINE_IMPORTSorDAPP_FMT_SINGLE_LINE_IMPORTS
Keep single imports on a single line even if they exceed line_length.
