Skip to content

Format settings ​

Every setting of custos format, grouped by what it lays out. Set them in the format.settings object of custos.json, or for one run with --set id=value; custos format --show-config prints the value each one takes and where it comes from. A keep value leaves that part of the layout as written.

Presets (the Formatting guide explains how to pick one; per is the default):

Risky settings change more than the layout and stay off unless allowed; in the preset tables, a cell such as false, risky: true gives the value a preset applies only when risky settings are allowed (--allow-risky or allowRisky).

File ​

SettingTypeValuesDescription
indent_styleenumspace, tab, keepIndent with spaces or tabs; keep leaves indentation as written.
indent_sizeintinteger, 0 or moreColumns per indentation level when indenting with spaces.
tab_widthintinteger, 0 or moreColumns a tab counts for when measuring line length.
continuation_indentenumone, keepIndentation of a line continuing a statement or list item: one level more than its first line (deeper levels written for nested operands are kept), or keep the offset written, alignment included.
assignment_chainenumone, stairsIndentation of a line starting with the = of a chained assignment written over several lines: one level more than the statement (one), or one level more than the line before (stairs).
line_endingenumlf, crlf, cr, keepLine break written between lines outside strings; keep uses the file's first line break.
final_newlinebooltrue, falseEnd a file of PHP code with exactly one line break.
trim_trailing_whitespacebooltrue, falseRemove spaces and tabs at the end of lines outside strings and inline HTML.
remove_bombooltrue, falseRemove a UTF-8 byte order mark.
closing_tagenumremove, keepRemove the ?> that ends a file containing only PHP code.
open_tag_own_linebooltrue, falsePut the <?php that starts a PHP-only file on its own line.
blank_line_after_open_tagbooltrue, falseLeave one blank line between the opening <?php line and the code.
max_blank_linesintinteger, 0 or moreMost consecutive blank lines kept anywhere; 0 keeps any number.
line_lengthintinteger, 0 or moreTarget width of a line in columns; wrapping and the line length report use it. 0 disables both.
wrapenumlong, offlong puts one item per line in lists that exceed line_length or are partly split; off keeps line breaks as written.
report_long_linesbooltrue, falseReport the lines that stay wider than line_length after formatting; a check then fails on them.
join_fitting_listsbooltrue, falseJoin a multi-line list back on one line when it fits and holds no comment.
branch_commentenumbody, nextIndentation of comments just before } else, } elseif, } catch or } finally: with the block they end (body), or with the next branch when written at the brace's level (next).
case_commentenumbody, labelIndentation of comments just before a case or default that follows another case: with the body of the case they end (body), or with the label after a return, break, continue or throw (label).

Preset values:

Settingpsr1psr12persymfonylaraveldrupal
indent_stylekeepspacespacespacespacespace
indent_size444442
tab_width444444
continuation_indentkeeponeoneoneoneone
assignment_chainoneoneoneoneonestairs
line_endingkeeplflflflflf
final_newlinefalsetruetruetruetruetrue
trim_trailing_whitespacefalsetruetruetruetruetrue
remove_bomtruetruetruetruetruetrue
closing_tagkeepremoveremoveremoveremoveremove
open_tag_own_linefalsetruetruetruetruetrue
blank_line_after_open_tagfalsetruetruetruetruetrue
max_blank_lines011111
line_length012012012012080
wrapofflonglonglongofflong
report_long_linesfalsefalsefalsefalsefalsefalse
join_fitting_listsfalsefalsefalsefalsefalsefalse
branch_commentbodybodybodynextbodybody
case_commentbodybodybodybodybodylabel

Braces ​

SettingTypeValuesDescription
class_braceenumnext_line, same_line, keepOpening brace of a class, interface, trait or enum.
function_braceenumnext_line, same_line, keepOpening brace of a function or method; after a signature split over several lines it always follows ) on the same line.
closure_braceenumnext_line, same_line, keepOpening brace of a closure.
anonymous_class_braceenumnext_line, same_line, keepOpening brace of an anonymous class.
control_braceenumnext_line, same_line, keepOpening brace of a control structure.
else_positionenumsame_line, next_line, keepWhether else and elseif follow the closing brace on its line or start the next one.
catch_positionenumsame_line, next_line, keepWhether catch and finally follow the closing brace on its line or start the next one.
single_line_closuresbooltrue, falseKeep a closure or anonymous class written on one line on one line.
empty_bodyenuminline, keepWrite the empty body of a class or function as {} on its declaration line.

Preset values:

Settingpsr1psr12persymfonylaraveldrupal
class_bracekeepnext_linenext_linenext_linenext_linesame_line
function_bracekeepnext_linenext_linenext_linenext_linesame_line
closure_bracekeepsame_linesame_linesame_linesame_linesame_line
anonymous_class_bracekeepsame_linesame_linesame_linenext_linesame_line
control_bracekeepsame_linesame_linesame_linesame_linesame_line
else_positionkeepsame_linesame_linesame_linesame_linenext_line
catch_positionkeepsame_linesame_linesame_linesame_linenext_line
single_line_closurestruefalsefalsetruefalsefalse
empty_bodykeepkeepinlinekeepinlinekeep

Lines ​

SettingTypeValuesDescription
statement_per_linebooltrue, falseStart each statement on its own line.
semicolon_lineenumjoin, keepMove a ; alone on its line to the end of the statement.
blank_line_after_throwbooltrue, falseKeep the blank lines that follow a throw statement; false removes them.
single_line_class_definitionbooltrue, falseWrite the extends and implements lists and the arguments of an anonymous class on the line of their class when it fits.
function_separationbooltrue, falseOne blank line before a function declared first in a block and after one declared last.
case_body_linebooltrue, falseStart the statements of a case on the line after it.
single_line_throwbooltrue, falseWrite a throw statement on one line, whatever its length, unless it holds a comment, a closure or a heredoc.
blank_line_after_namespacebooltrue, falseOne blank line after a namespace declaration.
blank_line_after_importsbooltrue, falseOne blank line after the last use import.
blank_line_between_import_groupsbooltrue, falseOne blank line between class, function and constant imports.
class_open_blank_lineenumone, none, keepBlank line after the opening brace of a class.
class_close_blank_lineenumone, none, keepBlank line before the closing brace of a class.
split_multiline_arraysbooltrue, falseWrite an array that spans several lines one item per line, also when only its last item spans lines.
trim_bracket_blank_linesbooltrue, falseRemove blank lines after an opening and before a closing bracket or parenthesis.
trim_block_blank_linesbooltrue, falseRemove blank lines after the opening and before the closing brace of a function or control structure.
blank_line_after_trait_usebooltrue, falseOne blank line between the trait imports of a class and its next member.
method_separationenumone, keepOne blank line between a method and the member before it.
property_separationenumone, none, keepBlank line between consecutive properties.
constant_separationenumone, none, keepBlank line between consecutive class constants.
case_separationbooltrue, falseOne blank line before a case or default that follows the statements of the previous one.
blank_line_beforelistlist of break, continue, declare, do, for, foreach, if, return, switch, throw, try, while, yieldStatements preceded by a blank line unless they open their block.

Preset values:

Settingpsr1psr12persymfonylaraveldrupal
statement_per_linefalsetruetruetruetruetrue
semicolon_linekeepkeepkeepjoinjoinjoin
blank_line_after_throwtruetruetruefalsefalsetrue
single_line_class_definitionfalsefalsefalsetruetruefalse
function_separationfalsefalsefalsefalsefalsetrue
case_body_linefalsetruetruetruefalsetrue
single_line_throwfalsefalsefalsetruefalsefalse
blank_line_after_namespacefalsetruetruetruetruetrue
blank_line_after_importsfalsetruetruetruetruetrue
blank_line_between_import_groupsfalsetruetruetruetruetrue
class_open_blank_linekeepnonenonenonenoneone
class_close_blank_linekeepnonenonenonenoneone
split_multiline_arraysfalsefalsefalsefalsefalsetrue
trim_bracket_blank_linesfalsefalsefalsetruefalsefalse
trim_block_blank_linesfalsetruetruetruetruefalse
blank_line_after_trait_usefalsetruetruetruetruetrue
method_separationkeepkeepkeeponeoneone
property_separationkeepkeepkeepkeeponekeep
constant_separationkeepkeepkeepkeeponekeep
case_separationfalsefalsefalsefalsefalsetrue
blank_line_before[][][]returncontinue, return[]

Spacing ​

SettingTypeValuesDescription
spacingbooltrue, falseNormalize the spaces between tokens on a line (keywords, operators, commas, brackets).
concat_spaceenumone, none, keepSpaces around the . operator.
binary_operator_spaceenumone, at_least_oneSpaces around binary and assignment operators; at_least_one keeps alignment.
cast_spaceenumone, none, keepSpace after a cast such as (int).
not_operator_spaceenumnone, oneSpace after the ! operator.
arrow_function_spaceenumnone, one, keepSpace between fn and (.
anonymous_class_spaceenumone, none, keepSpace between class and ( in new class(...).
catch_type_spaceenumone, none, keepSpaces around | between the exception types of a catch.
closure_spaceenumone, noneSpace between function and ( of a closure.

Preset values:

Settingpsr1psr12persymfonylaraveldrupal
spacingfalsetruetruetruetruetrue
concat_spacekeeponeonenonenoneone
binary_operator_spaceat_least_oneat_least_oneat_least_oneoneoneone
cast_spacekeepkeeponeoneoneone
not_operator_spacenonenonenonenoneonenone
arrow_function_spacekeepkeepnoneoneonekeep
anonymous_class_spacekeeponeonenonenoneone
catch_type_spacekeeponenonenonenoneone
closure_spaceoneoneoneoneoneone

Casing ​

SettingTypeValuesDescription
keyword_caseenumlower, keepCase of keywords.
constant_caseenumlower, upper, keepCase of true, false and null.
type_caseenumlower, keepCase of built-in type names in declarations.
magic_constant_caseenumupper, keepCase of magic constants such as __DIR__.
hex_caseenumupper, keepWrite the digits of hexadecimal numbers in uppercase and the prefixes of numbers (0x, 0b, 0o) in lowercase.
short_castbooltrue, falseWrite casts in their short lowercase form: (int), (bool), (float), (string).

Preset values:

Settingpsr1psr12persymfonylaraveldrupal
keyword_casekeeplowerlowerlowerlowerlower
constant_casekeeplowerlowerlowerlowerupper
type_casekeeplowerlowerlowerlowerlower
magic_constant_casekeepkeepkeepupperupperkeep
hex_casekeepkeepkeepupperupperkeep
short_castfalsetruetruetruetruetrue

Syntax ​

SettingTypeValuesDescription
trailing_commalistlist of arguments, arrays, closure_use, destructuring, match, parametersLists that end with a comma when split over several lines; arguments and closure use need PHP 7.3, parameters PHP 8.0.
single_line_trailing_commabooltrue, falseKeep a trailing comma in a list written on one line.
array_syntaxenumshort, long, keep[] or array() for array literals.
list_syntaxenumshort, long, keep[] or list() for destructuring (short needs PHP 7.1).
visibilityenumall, methods_properties, keepWrite the implicit public of class members that declare no visibility: methods, properties and constants (PHP 7.1), or methods and properties.
parameter_attribute_linebooltrue, falsePut the attributes of a parameter on a line of their own when the parameters are one per line.
null_type_lastbooltrue, falseWrite null last in a union type: string|null.
elseifbooltrue, falseWrite else if as elseif.
new_parenthesesenumadd, remove, keepParentheses after a class name in new without arguments.
standardize_not_equalsbooltrue, falseWrite <> as !=.
comment_spacingbooltrue, falsePut a space after // and #, and inside /* */ written on one line.
hash_commentbooltrue, falseWrite # comments as //.
operator_linebreakenumstart, start_booleans, keepMove an operator that ends a line to the start of the next: every binary operator, or only &&, ||, and, or, xor.

Preset values:

Settingpsr1psr12persymfonylaraveldrupal
trailing_comma[][]arguments, arrays, closure_use, destructuring, match, parametersarrays, destructuring, match, parametersarraysarrays, destructuring, parameters
single_line_trailing_commatruetruefalsefalsefalsefalse
array_syntaxkeepkeepshortshortshortshort
list_syntaxkeepkeepkeepshortshortkeep
visibilitykeepallallallmethods_propertiesall
parameter_attribute_linefalsefalsetruetruefalsetrue
null_type_lastfalsefalsetruetruefalsetrue
elseiffalsetruetruetruetruetrue
new_parentheseskeepaddaddaddremoveadd
standardize_not_equalsfalsefalsefalsetruetruetrue
comment_spacingfalsefalsefalsetruetruefalse
hash_commentfalsefalsefalsetruetruefalse
operator_linebreakkeepkeepstartstart_booleanskeepkeep

Imports ​

SettingTypeValuesDescription
import_orderenumalpha, length, noneSort use imports within each group, alphabetically (case-insensitive) or by length.
import_groupsenumclass_function_const, const_class_function, noneOrder of the class, function and constant import groups.
no_leading_import_slashbooltrue, falseRemove the leading \ of an imported name.
single_trait_per_statementbooltrue, falseSplit use A, B; in a class into one statement per trait (not when it adapts methods).
single_import_per_statementbooltrue, falseSplit use A, B; into one statement per import.

Preset values:

Settingpsr1psr12persymfonylaraveldrupal
import_ordernonenonenonealphaalphanone
import_groupsnoneclass_function_constclass_function_constclass_function_constconst_class_functionnone
no_leading_import_slashfalsetruetruetruetruetrue
single_trait_per_statementfalsetruetruetruefalsetrue
single_import_per_statementfalsetruetruetruetruetrue

Risky ​

SettingTypeValuesDescription
yoda (risky)enumyoda, regular, keepOrder of the operands of ==, !=, === and !== when one is a literal or constant: first (yoda) or last (regular).
single_quote (risky)booltrue, falseWrite double-quoted strings without escapes or interpolation in single quotes.
remove_unused_imports (risky)booltrue, falseRemove use imports the file never mentions, docblocks included.
declare_strict_types (risky)booltrue, falseAdd declare(strict_types=1); to PHP-only files that lack it (PHP 7.0+).
increment_style (risky)enumpre, post, keepWrite a standalone increment or decrement statement as ++$i or $i++.
ordered_traits (risky)booltrue, falseSort the traits of a use statement in a class alphabetically (case-insensitive).
heredoc_to_nowdoc (risky)booltrue, falseWrite a heredoc without escapes or interpolation as a nowdoc.

Preset values:

Settingpsr1psr12persymfonylaraveldrupal
yodakeepkeepkeepkeep, risky: yodakeep, risky: regularkeep
single_quotefalsefalsefalsefalse, risky: truefalse, risky: truefalse
remove_unused_importsfalsefalsefalsefalse, risky: truefalse, risky: truefalse
declare_strict_typesfalsefalsefalsefalsefalsefalse
increment_stylekeepkeepkeepkeep, risky: prekeep, risky: postkeep
ordered_traitsfalsefalsefalsefalsefalse, risky: truefalse
heredoc_to_nowdocfalsefalsefalsefalsefalse, risky: truefalse

Released under the MIT License. Native rules and rules modeled on Php Inspections (EA Extended); independent clean-room implementation.