Mezery
Sekce spacing rozhoduje o mezerách na řádku: kolem operátorů, za čárkou, uvnitř závorek,
mezi jménem funkce a závorkou, za klíčovým slovem, kolem -> a ::, v deklaraci typu a
v komentáři.
U mezer je hodnotou tvar a každý tvar má slovo i ukázku kódu. Do konfigurace můžete napsat kterékoli z nich, a ukázka se čte nejlíp, protože říká přesně to, co uvidíte v kódu:
spacing:
concatenation: '$a.$b'
arrowFunction: 'fn ($x) => $x'
cast: '(int) $x'
catchTypes: 'catch (A|B $e)'
Ukázku DressCode nečte jako kód, jen ji porovná s ukázkami, které klíč zná; zapsat ji lze i slovem,
concatenation: compact. Neznámá ukázka je chyba, která vypíše ty známé.
$label = 'Item '.$name . ' x'.$count; // Expected no whitespace before the `.` operator. // Expected no whitespace after the `.` operator.
$double = fn($x) => $x * 2; // Expected a single space after the `fn` keyword.
$id = (int)$row['id']; // Expected a single space after the cast.
$label = 'Item '.$name.' x'.$count;
$double = fn ($x) => $x * 2;
$id = (int) $row['id'];
Mezera kolem operátoru, který stojí na zlomu řádku, je věc odsazení a sekce multiline, ne téhle. Kde víc mezer zarovnává sloupce, rozhodují
parametry binaryOperatorAlignment, commaAlignment a ternaryAlignment, jestli zarovnání
smí zůstat; DressCode sloupce sám nikdy nezarovnává.
spacing.arrayBrackets
The whitespace inside the brackets of an array.
compactnebo'[1, 2]': none insidekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette compact,
symfony compact · pokrývá
trim_array_spaces, SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace
spacing.classHead
The spaces between the words of the head of a class declaration, which stays on one line unless a comment breaks it, the brace and the implemented interfaces being free to take the next one.
spacednebo'class Foo extends Bar implements Baz': single spaceskeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spaced, psr12 spaced, nette
spaced, symfony spaced · pokrývá
PSR12.Classes.AnonClassDeclaration, PSR2.Classes.ClassDeclaration.SpaceBeforeKeyword
spacing.anonymousClass
The space between class and the arguments of an anonymous class.
spacednebo'new class ($a)': a single space before the argumentscompactnebo'new class($a)': no space before the argumentskeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spaced, psr12 spaced, nette
spaced, symfony compact · pokrývá class_definition,
PSR12.Classes.AnonClassDeclaration, PSR2.Classes.ClassDeclaration.SpaceBeforeKeyword
spacing.comment
The space after the marker of a comment and before the closing one, unless another / or * follows the
marker, as in a //// ruler; doc comments are the matter of the phpDoc rules.
spacednebo'// text': a single space after the markerkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette spaced,
symfony spaced · pokrývá
PhpCsFixerCustomFixers/comment_surrounded_by_spaces, single_line_comment_spacing
spacing.commentAfterCode
The whitespace before a comment that follows code on its line.
spacednebo'$a; // text': at least one spacekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette spaced,
symfony spaced · pokrývá
PhpCsFixerCustomFixers/comment_surrounded_by_spaces, single_line_comment_spacing
spacing.commentAfterCodeAlignment
Whether a comment following code may be aligned by more spaces.
any: more spaces staynone: exactly one space
Parametr, výchozí any · standardy: perCs any, psr12 any, nette
any, symfony any · pokrývá
PhpCsFixerCustomFixers/comment_surrounded_by_spaces, single_line_comment_spacing
spacing.switchCase
The whitespace before the colon of a case.
compactnebo'case 1:': none before the colonkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs compact, psr12 compact, nette
compact, symfony compact · pokrývá switch_case_space,
PSR2.ControlStructures.SwitchDeclaration, PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonCASE
spacing.binaryOperator
The spaces around a binary operator other than ., an assignment, instanceof, => and
the = of a default, unless it sits at a line break; an assignment and => stay on the line of what is
before them, instanceof and what follows a comparison, a bitwise operator or a shift on the line of the operator,
unless the line would grow too wide.
spacednebo'$a + $b': a single space aroundkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spaced, psr12 spaced, nette
spaced, symfony spaced · pokrývá binary_operator_spaces,
PSR12.Operators.OperatorSpacing, Squiz.ControlStructures.ForEachLoopDeclaration,
Squiz.WhiteSpace.LogicalOperatorSpacing, Squiz.WhiteSpace.OperatorSpacing
Týká se aritmetických, porovnávacích, logických a bitových operátorů, ??, přiřazení včetně
+= a ??=, instanceof, => a = výchozí hodnoty. Tečka má
vlastní klíč concatenation, protože o ní se styly rozcházejí.
spacing:
binaryOperator: '$a + $b'
$total=$price*$count; // Expected at least one space before the `=` operator. // Expected at least one space after the `=` operator. // Expected at least one space before the `*` operator. // Expected at least one space after the `*` operator.
$label = $count>1 ? 'items' : 'item'; // Expected at least one space before the `>` operator. // Expected at least one space after the `>` operator.
$map = ['a'=>1, 'b' => 2]; // Expected at least one space before the double arrow. // Expected at least one space after the double arrow.
$aligned = 1;
$alsoFine = 2;
$total = $price * $count;
$label = $count > 1 ? 'items' : 'item';
$map = ['a' => 1, 'b' => 2];
$aligned = 1;
$alsoFine = 2;
Poslední dva řádky zůstaly: zarovnání mezerami dovoluje výchozí hodnota parametru
binaryOperatorAlignment.
spacing.binaryOperatorAlignment
Which whitespace wider than a single space around an operator stays, aligning a column of assignments or of array items; alignment is never made.
none: more spaces collapse to onespaces: spaces aligning a column staytabs: tabs aligning a column stayany: any alignment stays
Parametr, výchozí spaces · standardy: perCs spaces, psr12
spaces, nette spaces, symfony none · pokrývá binary_operator_spaces,
PSR12.Operators.OperatorSpacing, Squiz.ControlStructures.ForEachLoopDeclaration,
Squiz.WhiteSpace.LogicalOperatorSpacing, Squiz.WhiteSpace.OperatorSpacing
spacing:
binaryOperator: '$a + $b'
binaryOperatorAlignment: none
$aligned = 1; // Expected a single space before the `=` operator.
$alsoFine = 2; // Expected a single space before the `=` operator.
$aligned = 1;
$alsoFine = 2;
spacing.cast
The space between a cast and its operand, which stays on the line of the cast.
spacednebo'(int) $x': a single space after the castcompactnebo'(int)$x': no space after the castkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spaced, psr12 spaced, nette
spaced, symfony spaced · pokrývá cast_spaces
spacing.concatenation
The space around the concatenation operator, unless it sits at a line break.
spacednebo'$a . $b': a single space aroundcompactnebo'$a.$b': no space aroundkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spaced, psr12 spaced, nette
spaced, symfony compact · pokrývá concat_space,
PSR12.Operators.OperatorSpacing, Squiz.Strings.ConcatenationSpacing
spacing.doubleColon
The whitespace around the double colon.
compactnebo'Foo::bar()': none aroundkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette compact,
symfony keep · pokrývá
no_space_around_double_colon, Squiz.WhiteSpace.ScopeKeywordSpacing
spacing.objectOperator
The whitespace around the object operator.
compactnebo'$a->b()': none aroundkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette compact,
symfony compact · pokrývá
object_operator_without_whitespace, Squiz.WhiteSpace.ObjectOperatorSpacing
spacing.offsetBrackets
The whitespace around and inside the brackets of an offset access.
compactnebo'$a[0]': none around and insidekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette compact,
symfony compact · pokrývá no_spaces_around_offset, Squiz.Arrays.ArrayBracketSpacing
spacing.reference
The whitespace between & and its operand.
compactnebo'&$x': none betweenkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs compact, psr12 compact, nette
compact, symfony compact ·
pokrývá SlevomatCodingStandard.Operators.ReferenceSpacing
spacing.spread
The whitespace between ... and its operand.
compactnebo'...$x': none betweenkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs compact, psr12 compact, nette
compact, symfony compact ·
pokrývá SlevomatCodingStandard.Operators.SpreadOperatorSpacing
spacing.ternary
The whitespace around ? and : of a ternary, and around ?: as a whole, unless the
operator sits at a line break.
spacednebo'$a ? $b : $c': whitespace around?and:keep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spaced, psr12 spaced, nette
spaced, symfony spaced · pokrývá
ternary_operator_spaces, PSR12.Operators.OperatorSpacing
spacing.ternaryAlignment
Whether more spaces around ? and : stay.
any: more spaces staynone: exactly one space
Parametr, výchozí any · standardy: perCs any, psr12 any, nette
none, symfony any · pokrývá
ternary_operator_spaces, PSR12.Operators.OperatorSpacing
spacing.unaryOperator
The whitespace between a unary operator and its operand, which stay on one line, and inside a variable variable,
$$a and ${'a'}.
compactnebo'-$x': no space after the operatorkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs compact, psr12 compact, nette
compact, symfony compact · pokrývá unary_operator_spaces,
Generic.WhiteSpace.IncrementDecrementSpacing,
SlevomatCodingStandard.Operators.NegationOperatorSpacing, Squiz.WhiteSpace.OperatorSpacing.Unary
spacing.unaryOperatorsWithSpace
The operators whose operand may stand apart from them, as written, ! $x.
- seznam z těchto slov:
++: increment--: decrement!: negation-: minus+: plus~: bitwise negation@: error suppression
Parametr, výchozí [] · standardy: perCs ['!'], psr12 ['!'],
nette [], symfony [] · pokrývá Generic.WhiteSpace.IncrementDecrementSpacing,
SlevomatCodingStandard.Operators.NegationOperatorSpacing, Squiz.WhiteSpace.OperatorSpacing.Unary
spacing.declare
The whitespace inside a declare statement.
compactnebo'declare(strict_types=1)': none insidekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs compact, psr12 compact, nette
compact, symfony compact · pokrývá declare_equal_normalize,
declare_parentheses, PSR12.Files.DeclareStatement
spacing.call
The whitespace between the name of a function and its parenthesis, of a call and of a declaration alike.
compactnebo'foo($a, $b)': no space before the parenthesiskeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs compact, psr12 compact, nette
compact, symfony compact · pokrývá no_spaces_after_function_name,
Generic.Functions.FunctionCallArgumentSpacing.SpaceBeforeOpenBracket,
PSR2.Methods.FunctionCallSignature, Squiz.Functions.FunctionDeclaration
spacing.namedArgument
The whitespace around the colon of a named argument.
spacedAfternebo'foo(name: $x)': none before the colon, a single space afterkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spacedAfter, psr12 keep, nette
spacedAfter, symfony spacedAfter ·
pokrývá SlevomatCodingStandard.Functions.NamedArgumentSpacing
spacing.typeDeclaration
The whitespace of a type declaration, which stays on one line with what it describes: none inside a type, a single space
between a type and the name it declares, ): int for a return type and enum Suit: string for a
backing type.
compactnebo'?int $x': none inside a type, a single space before the namekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs compact, psr12 compact, nette
compact, symfony compact · pokrývá compact_nullable_type_declaration,
return_type_declaration, PSR12.Functions.NullableTypeDeclaration,
PSR12.Functions.ReturnTypeDeclaration, SlevomatCodingStandard.Classes.BackedEnumTypeSpacing,
SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing,
SlevomatCodingStandard.TypeHints.PropertyTypeHintSpacing, SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing
spacing.catchTypes
The space around the bar between the types of a catch.
spacednebo'catch (A | B $e)': a single space around the barcompactnebo'catch (A|B $e)': no space around the barkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs compact, psr12 spaced, nette
compact, symfony compact · pokrývá compact_nullable_type_declaration,
return_type_declaration, PSR12.Functions.NullableTypeDeclaration,
PSR12.Functions.ReturnTypeDeclaration, SlevomatCodingStandard.Classes.BackedEnumTypeSpacing,
SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing,
SlevomatCodingStandard.TypeHints.PropertyTypeHintSpacing, SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing
spacing.attribute
The whitespace inside the brackets of an attribute group and before the parenthesis of its arguments.
compactnebo'#[Foo($a)]': none inside the brackets, none before the parenthesiskeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs compact, psr12 keep, nette
compact, symfony compact · pokrývá attribute_block_no_spaces
spacing.comma
The whitespace around a comma, which stays on the line of what is before it, a line ending after it being free.
spacedAfternebo'$a, $b': none before, a single space afterkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spacedAfter, psr12 spacedAfter, nette
spacedAfter, symfony spacedAfter · pokrývá no_whitespace_before_comma_in_array,
whitespace_after_comma_in_array,
Generic.Functions.FunctionCallArgumentSpacing, Squiz.Functions.FunctionDeclarationArgumentSpacing
spacing.commaAlignment
Which whitespace wider than a single space after a comma stays, aligning the columns of a table; alignment is never made.
tabs: tabs aligning a column stayspaces: spaces aligning a column stayany: any alignment staysnone: more whitespace collapses to a single space
Parametr, výchozí tabs · standardy: perCs none, psr12 none,
nette tabs, symfony any · pokrývá no_whitespace_before_comma_in_array,
whitespace_after_comma_in_array,
Generic.Functions.FunctionCallArgumentSpacing, Squiz.Functions.FunctionDeclarationArgumentSpacing
spacing.languageConstruct
The space after return, throw, yield, print, include,
clone, new and the other keywords followed by code, which also stays on their line, and inside the
braces of abbreviated property hooks; the braces of a group use hug their names.
spacednebo'return $x': a single spacekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spaced, psr12 spaced, nette
spaced, symfony spaced · pokrývá function_declaration,
single_space_around_construct, Generic.WhiteSpace.LanguageConstructSpacing,
PSR12.Traits.UseDeclaration, PSR2.ControlStructures.SwitchDeclaration,
SlevomatCodingStandard.Functions.ArrowFunctionDeclaration,
Squiz.ControlStructures.ForEachLoopDeclaration, Squiz.Functions.FunctionDeclaration
spacing.controlKeyword
The space after if, elseif, while, for, foreach,
switch, match and catch, and before the brace or the body a structure opens on its line;
the colon of the alternative syntax hugs what is before it.
spacednebo'if ($a)': a single spacekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spaced, psr12 spaced, nette
spaced, symfony spaced · pokrývá function_declaration,
single_space_around_construct, Generic.WhiteSpace.LanguageConstructSpacing,
PSR12.Traits.UseDeclaration, PSR2.ControlStructures.SwitchDeclaration,
SlevomatCodingStandard.Functions.ArrowFunctionDeclaration,
Squiz.ControlStructures.ForEachLoopDeclaration, Squiz.Functions.FunctionDeclaration
spacing.connectingKeyword
The space around else, elseif, catch, finally, the while of a
do, as, insteadof and the use of a closure, which stay on the line of what is
before them.
spacednebo'} else {': a single spacekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spaced, psr12 spaced, nette
spaced, symfony spaced · pokrývá function_declaration,
single_space_around_construct, Generic.WhiteSpace.LanguageConstructSpacing,
PSR12.Traits.UseDeclaration, PSR2.ControlStructures.SwitchDeclaration,
SlevomatCodingStandard.Functions.ArrowFunctionDeclaration,
Squiz.ControlStructures.ForEachLoopDeclaration, Squiz.Functions.FunctionDeclaration
spacing.closure
The space after function.
spacednebo'function ($x)': a single spacekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spaced, psr12 spaced, nette
spaced, symfony spaced · pokrývá function_declaration,
Generic.WhiteSpace.LanguageConstructSpacing, PSR12.Traits.UseDeclaration,
PSR2.ControlStructures.SwitchDeclaration, SlevomatCodingStandard.Functions.ArrowFunctionDeclaration,
Squiz.ControlStructures.ForEachLoopDeclaration, Squiz.Functions.FunctionDeclaration
spacing.modifiers
The space after a modifier.
spacednebo'final public static function': a single spacekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs spaced, psr12 spaced, nette
spaced, symfony spaced · pokrývá function_declaration,
Generic.WhiteSpace.LanguageConstructSpacing, PSR12.Traits.UseDeclaration,
PSR2.ControlStructures.SwitchDeclaration, SlevomatCodingStandard.Functions.ArrowFunctionDeclaration,
Squiz.ControlStructures.ForEachLoopDeclaration, Squiz.Functions.FunctionDeclaration
spacing.arrowFunction
The space between fn and its parenthesis.
compactnebo'fn($x) => $x': no space before the parenthesisspacednebo'fn ($x) => $x': a single spacekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs compact, psr12 keep, nette
compact, symfony spaced · pokrývá function_declaration,
Generic.WhiteSpace.LanguageConstructSpacing, PSR12.Traits.UseDeclaration,
PSR2.ControlStructures.SwitchDeclaration, SlevomatCodingStandard.Functions.ArrowFunctionDeclaration,
Squiz.ControlStructures.ForEachLoopDeclaration, Squiz.Functions.FunctionDeclaration
spacing.parentheses
The whitespace inside parentheses.
compactnebo'($a)': none insidekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs compact, psr12 compact, nette
compact, symfony compact · pokrývá no_spaces_inside_parenthesis,
spaces_inside_parentheses, PSR12.Classes.AnonClassDeclaration,
PSR12.ControlStructures.ControlStructureSpacing, PSR2.ControlStructures.ControlStructureSpacing,
PSR2.Methods.FunctionCallSignature,
Squiz.ControlStructures.ForEachLoopDeclaration, Squiz.ControlStructures.ForLoopDeclaration
spacing.beforeSemicolon
The whitespace before a semicolon, which stays on the line of what it ends.
compactnebo'$a;': no space before a semicolonkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs compact, psr12 keep, nette
compact, symfony compact · pokrývá no_singleline_whitespace_before_semicolons,
space_after_semicolon, PSR12.Traits.UseDeclaration,
Squiz.ControlStructures.ForLoopDeclaration,
Squiz.Functions.FunctionDeclaration, Squiz.WhiteSpace.SemicolonSpacing
spacing.semicolon
The whitespace after a semicolon that more code follows on its line.
spacednebo'for ($i = 0; $i < 5; $i++)': a single space after a semicolonkeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette spaced,
symfony spaced · pokrývá space_after_semicolon, PSR12.Traits.UseDeclaration,
Squiz.ControlStructures.ForLoopDeclaration,
Squiz.Functions.FunctionDeclaration, Squiz.WhiteSpace.SemicolonSpacing