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
| Setting | Type | Values | Description |
|---|---|---|---|
indent_style | enum | space, tab, keep | Indent with spaces or tabs; keep leaves indentation as written. |
indent_size | int | integer, 0 or more | Columns per indentation level when indenting with spaces. |
tab_width | int | integer, 0 or more | Columns a tab counts for when measuring line length. |
continuation_indent | enum | one, keep | Indentation 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_chain | enum | one, stairs | Indentation 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_ending | enum | lf, crlf, cr, keep | Line break written between lines outside strings; keep uses the file's first line break. |
final_newline | bool | true, false | End a file of PHP code with exactly one line break. |
trim_trailing_whitespace | bool | true, false | Remove spaces and tabs at the end of lines outside strings and inline HTML. |
remove_bom | bool | true, false | Remove a UTF-8 byte order mark. |
closing_tag | enum | remove, keep | Remove the ?> that ends a file containing only PHP code. |
open_tag_own_line | bool | true, false | Put the <?php that starts a PHP-only file on its own line. |
blank_line_after_open_tag | bool | true, false | Leave one blank line between the opening <?php line and the code. |
max_blank_lines | int | integer, 0 or more | Most consecutive blank lines kept anywhere; 0 keeps any number. |
line_length | int | integer, 0 or more | Target width of a line in columns; wrapping and the line length report use it. 0 disables both. |
wrap | enum | long, off | long puts one item per line in lists that exceed line_length or are partly split; off keeps line breaks as written. |
report_long_lines | bool | true, false | Report the lines that stay wider than line_length after formatting; a check then fails on them. |
join_fitting_lists | bool | true, false | Join a multi-line list back on one line when it fits and holds no comment. |
branch_comment | enum | body, next | Indentation 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_comment | enum | body, label | Indentation 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:
| Setting | psr1 | psr12 | per | symfony | laravel | drupal |
|---|---|---|---|---|---|---|
indent_style | keep | space | space | space | space | space |
indent_size | 4 | 4 | 4 | 4 | 4 | 2 |
tab_width | 4 | 4 | 4 | 4 | 4 | 4 |
continuation_indent | keep | one | one | one | one | one |
assignment_chain | one | one | one | one | one | stairs |
line_ending | keep | lf | lf | lf | lf | lf |
final_newline | false | true | true | true | true | true |
trim_trailing_whitespace | false | true | true | true | true | true |
remove_bom | true | true | true | true | true | true |
closing_tag | keep | remove | remove | remove | remove | remove |
open_tag_own_line | false | true | true | true | true | true |
blank_line_after_open_tag | false | true | true | true | true | true |
max_blank_lines | 0 | 1 | 1 | 1 | 1 | 1 |
line_length | 0 | 120 | 120 | 120 | 120 | 80 |
wrap | off | long | long | long | off | long |
report_long_lines | false | false | false | false | false | false |
join_fitting_lists | false | false | false | false | false | false |
branch_comment | body | body | body | next | body | body |
case_comment | body | body | body | body | body | label |
Braces
| Setting | Type | Values | Description |
|---|---|---|---|
class_brace | enum | next_line, same_line, keep | Opening brace of a class, interface, trait or enum. |
function_brace | enum | next_line, same_line, keep | Opening brace of a function or method; after a signature split over several lines it always follows ) on the same line. |
closure_brace | enum | next_line, same_line, keep | Opening brace of a closure. |
anonymous_class_brace | enum | next_line, same_line, keep | Opening brace of an anonymous class. |
control_brace | enum | next_line, same_line, keep | Opening brace of a control structure. |
else_position | enum | same_line, next_line, keep | Whether else and elseif follow the closing brace on its line or start the next one. |
catch_position | enum | same_line, next_line, keep | Whether catch and finally follow the closing brace on its line or start the next one. |
single_line_closures | bool | true, false | Keep a closure or anonymous class written on one line on one line. |
empty_body | enum | inline, keep | Write the empty body of a class or function as {} on its declaration line. |
Preset values:
| Setting | psr1 | psr12 | per | symfony | laravel | drupal |
|---|---|---|---|---|---|---|
class_brace | keep | next_line | next_line | next_line | next_line | same_line |
function_brace | keep | next_line | next_line | next_line | next_line | same_line |
closure_brace | keep | same_line | same_line | same_line | same_line | same_line |
anonymous_class_brace | keep | same_line | same_line | same_line | next_line | same_line |
control_brace | keep | same_line | same_line | same_line | same_line | same_line |
else_position | keep | same_line | same_line | same_line | same_line | next_line |
catch_position | keep | same_line | same_line | same_line | same_line | next_line |
single_line_closures | true | false | false | true | false | false |
empty_body | keep | keep | inline | keep | inline | keep |
Lines
| Setting | Type | Values | Description |
|---|---|---|---|
statement_per_line | bool | true, false | Start each statement on its own line. |
semicolon_line | enum | join, keep | Move a ; alone on its line to the end of the statement. |
blank_line_after_throw | bool | true, false | Keep the blank lines that follow a throw statement; false removes them. |
single_line_class_definition | bool | true, false | Write the extends and implements lists and the arguments of an anonymous class on the line of their class when it fits. |
function_separation | bool | true, false | One blank line before a function declared first in a block and after one declared last. |
case_body_line | bool | true, false | Start the statements of a case on the line after it. |
single_line_throw | bool | true, false | Write a throw statement on one line, whatever its length, unless it holds a comment, a closure or a heredoc. |
blank_line_after_namespace | bool | true, false | One blank line after a namespace declaration. |
blank_line_after_imports | bool | true, false | One blank line after the last use import. |
blank_line_between_import_groups | bool | true, false | One blank line between class, function and constant imports. |
class_open_blank_line | enum | one, none, keep | Blank line after the opening brace of a class. |
class_close_blank_line | enum | one, none, keep | Blank line before the closing brace of a class. |
split_multiline_arrays | bool | true, false | Write an array that spans several lines one item per line, also when only its last item spans lines. |
trim_bracket_blank_lines | bool | true, false | Remove blank lines after an opening and before a closing bracket or parenthesis. |
trim_block_blank_lines | bool | true, false | Remove blank lines after the opening and before the closing brace of a function or control structure. |
blank_line_after_trait_use | bool | true, false | One blank line between the trait imports of a class and its next member. |
method_separation | enum | one, keep | One blank line between a method and the member before it. |
property_separation | enum | one, none, keep | Blank line between consecutive properties. |
constant_separation | enum | one, none, keep | Blank line between consecutive class constants. |
case_separation | bool | true, false | One blank line before a case or default that follows the statements of the previous one. |
blank_line_before | list | list of break, continue, declare, do, for, foreach, if, return, switch, throw, try, while, yield | Statements preceded by a blank line unless they open their block. |
Preset values:
| Setting | psr1 | psr12 | per | symfony | laravel | drupal |
|---|---|---|---|---|---|---|
statement_per_line | false | true | true | true | true | true |
semicolon_line | keep | keep | keep | join | join | join |
blank_line_after_throw | true | true | true | false | false | true |
single_line_class_definition | false | false | false | true | true | false |
function_separation | false | false | false | false | false | true |
case_body_line | false | true | true | true | false | true |
single_line_throw | false | false | false | true | false | false |
blank_line_after_namespace | false | true | true | true | true | true |
blank_line_after_imports | false | true | true | true | true | true |
blank_line_between_import_groups | false | true | true | true | true | true |
class_open_blank_line | keep | none | none | none | none | one |
class_close_blank_line | keep | none | none | none | none | one |
split_multiline_arrays | false | false | false | false | false | true |
trim_bracket_blank_lines | false | false | false | true | false | false |
trim_block_blank_lines | false | true | true | true | true | false |
blank_line_after_trait_use | false | true | true | true | true | true |
method_separation | keep | keep | keep | one | one | one |
property_separation | keep | keep | keep | keep | one | keep |
constant_separation | keep | keep | keep | keep | one | keep |
case_separation | false | false | false | false | false | true |
blank_line_before | [] | [] | [] | return | continue, return | [] |
Spacing
| Setting | Type | Values | Description |
|---|---|---|---|
spacing | bool | true, false | Normalize the spaces between tokens on a line (keywords, operators, commas, brackets). |
concat_space | enum | one, none, keep | Spaces around the . operator. |
binary_operator_space | enum | one, at_least_one | Spaces around binary and assignment operators; at_least_one keeps alignment. |
cast_space | enum | one, none, keep | Space after a cast such as (int). |
not_operator_space | enum | none, one | Space after the ! operator. |
arrow_function_space | enum | none, one, keep | Space between fn and (. |
anonymous_class_space | enum | one, none, keep | Space between class and ( in new class(...). |
catch_type_space | enum | one, none, keep | Spaces around | between the exception types of a catch. |
closure_space | enum | one, none | Space between function and ( of a closure. |
Preset values:
| Setting | psr1 | psr12 | per | symfony | laravel | drupal |
|---|---|---|---|---|---|---|
spacing | false | true | true | true | true | true |
concat_space | keep | one | one | none | none | one |
binary_operator_space | at_least_one | at_least_one | at_least_one | one | one | one |
cast_space | keep | keep | one | one | one | one |
not_operator_space | none | none | none | none | one | none |
arrow_function_space | keep | keep | none | one | one | keep |
anonymous_class_space | keep | one | one | none | none | one |
catch_type_space | keep | one | none | none | none | one |
closure_space | one | one | one | one | one | one |
Casing
| Setting | Type | Values | Description |
|---|---|---|---|
keyword_case | enum | lower, keep | Case of keywords. |
constant_case | enum | lower, upper, keep | Case of true, false and null. |
type_case | enum | lower, keep | Case of built-in type names in declarations. |
magic_constant_case | enum | upper, keep | Case of magic constants such as __DIR__. |
hex_case | enum | upper, keep | Write the digits of hexadecimal numbers in uppercase and the prefixes of numbers (0x, 0b, 0o) in lowercase. |
short_cast | bool | true, false | Write casts in their short lowercase form: (int), (bool), (float), (string). |
Preset values:
| Setting | psr1 | psr12 | per | symfony | laravel | drupal |
|---|---|---|---|---|---|---|
keyword_case | keep | lower | lower | lower | lower | lower |
constant_case | keep | lower | lower | lower | lower | upper |
type_case | keep | lower | lower | lower | lower | lower |
magic_constant_case | keep | keep | keep | upper | upper | keep |
hex_case | keep | keep | keep | upper | upper | keep |
short_cast | false | true | true | true | true | true |
Syntax
| Setting | Type | Values | Description |
|---|---|---|---|
trailing_comma | list | list of arguments, arrays, closure_use, destructuring, match, parameters | Lists 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_comma | bool | true, false | Keep a trailing comma in a list written on one line. |
array_syntax | enum | short, long, keep | [] or array() for array literals. |
list_syntax | enum | short, long, keep | [] or list() for destructuring (short needs PHP 7.1). |
visibility | enum | all, methods_properties, keep | Write the implicit public of class members that declare no visibility: methods, properties and constants (PHP 7.1), or methods and properties. |
parameter_attribute_line | bool | true, false | Put the attributes of a parameter on a line of their own when the parameters are one per line. |
null_type_last | bool | true, false | Write null last in a union type: string|null. |
elseif | bool | true, false | Write else if as elseif. |
new_parentheses | enum | add, remove, keep | Parentheses after a class name in new without arguments. |
standardize_not_equals | bool | true, false | Write <> as !=. |
comment_spacing | bool | true, false | Put a space after // and #, and inside /* */ written on one line. |
hash_comment | bool | true, false | Write # comments as //. |
operator_linebreak | enum | start, start_booleans, keep | Move an operator that ends a line to the start of the next: every binary operator, or only &&, ||, and, or, xor. |
Preset values:
| Setting | psr1 | psr12 | per | symfony | laravel | drupal |
|---|---|---|---|---|---|---|
trailing_comma | [] | [] | arguments, arrays, closure_use, destructuring, match, parameters | arrays, destructuring, match, parameters | arrays | arrays, destructuring, parameters |
single_line_trailing_comma | true | true | false | false | false | false |
array_syntax | keep | keep | short | short | short | short |
list_syntax | keep | keep | keep | short | short | keep |
visibility | keep | all | all | all | methods_properties | all |
parameter_attribute_line | false | false | true | true | false | true |
null_type_last | false | false | true | true | false | true |
elseif | false | true | true | true | true | true |
new_parentheses | keep | add | add | add | remove | add |
standardize_not_equals | false | false | false | true | true | true |
comment_spacing | false | false | false | true | true | false |
hash_comment | false | false | false | true | true | false |
operator_linebreak | keep | keep | start | start_booleans | keep | keep |
Imports
| Setting | Type | Values | Description |
|---|---|---|---|
import_order | enum | alpha, length, none | Sort use imports within each group, alphabetically (case-insensitive) or by length. |
import_groups | enum | class_function_const, const_class_function, none | Order of the class, function and constant import groups. |
no_leading_import_slash | bool | true, false | Remove the leading \ of an imported name. |
single_trait_per_statement | bool | true, false | Split use A, B; in a class into one statement per trait (not when it adapts methods). |
single_import_per_statement | bool | true, false | Split use A, B; into one statement per import. |
Preset values:
| Setting | psr1 | psr12 | per | symfony | laravel | drupal |
|---|---|---|---|---|---|---|
import_order | none | none | none | alpha | alpha | none |
import_groups | none | class_function_const | class_function_const | class_function_const | const_class_function | none |
no_leading_import_slash | false | true | true | true | true | true |
single_trait_per_statement | false | true | true | true | false | true |
single_import_per_statement | false | true | true | true | true | true |
Risky
| Setting | Type | Values | Description |
|---|---|---|---|
yoda (risky) | enum | yoda, regular, keep | Order of the operands of ==, !=, === and !== when one is a literal or constant: first (yoda) or last (regular). |
single_quote (risky) | bool | true, false | Write double-quoted strings without escapes or interpolation in single quotes. |
remove_unused_imports (risky) | bool | true, false | Remove use imports the file never mentions, docblocks included. |
declare_strict_types (risky) | bool | true, false | Add declare(strict_types=1); to PHP-only files that lack it (PHP 7.0+). |
increment_style (risky) | enum | pre, post, keep | Write a standalone increment or decrement statement as ++$i or $i++. |
ordered_traits (risky) | bool | true, false | Sort the traits of a use statement in a class alphabetically (case-insensitive). |
heredoc_to_nowdoc (risky) | bool | true, false | Write a heredoc without escapes or interpolation as a nowdoc. |
Preset values:
| Setting | psr1 | psr12 | per | symfony | laravel | drupal |
|---|---|---|---|---|---|---|
yoda | keep | keep | keep | keep, risky: yoda | keep, risky: regular | keep |
single_quote | false | false | false | false, risky: true | false, risky: true | false |
remove_unused_imports | false | false | false | false, risky: true | false, risky: true | false |
declare_strict_types | false | false | false | false | false | false |
increment_style | keep | keep | keep | keep, risky: pre | keep, risky: post | keep |
ordered_traits | false | false | false | false | false, risky: true | false |
heredoc_to_nowdoc | false | false | false | false | false, risky: true | false |
