Odsazení
Tabulátor, nebo čtyři mezery? Sekce indentation rozhoduje, čím a o kolik se odsazuje PHP kód,
i o kolik úrovní se odsadí řádek, který pokračuje výrazem, ternárním operátorem nebo řetězem volání.
Odsazení DressCode neodvozuje z předchozího řádku, ale ze syntaktického stromu: každý řádek dostane tolik úrovní,
kolik konstrukcí ho obklopuje, a jednou úrovní je unit. Jeden špatně odsazený řádek proto nestrhne řádky
pod sebou a nález řekne, jaké odsazení se čekalo a jaké se našlo. Ostatní klíče sekce rozhodují o řádcích, které
pokračují: o kolik úrovní se odsadí řádek začínající operátorem, ? nebo : ternárního
operátoru, case ve switch nebo článkem řetězu volání.
indentation:
unit: '4 spaces'
tabWidth: 4
chain: flat
switchCase: 1
Kde je unit keep, nic se nehlásí a řádky zůstanou, kde jsou. Kód, který DressCode napíše
nově, třeba rozepsané volání, se ale nějak odsadit musí, a tak dostane tabulátor. Projekt, který odsazuje mezerami, proto
unit nastaví vždy; mají ho všechny standardy.
indentation:
unit: '4 spaces'
function total(array $items): int
{
$sum = 0; // Expected the statement indented by 4 spaces, 1 tab found.
foreach ($items as $item) { // Expected the statement indented by 4 spaces, 1 tab found.
$sum += $item->price; // Expected the statement indented by 8 spaces, 2 tabs found.
} // Expected the closing brace indented by 4 spaces, 1 tab found.
return $sum; // Expected the statement indented by 4 spaces, 1 tab found.
}
function total(array $items): int
{
$sum = 0;
foreach ($items as $item) {
$sum += $item->price;
}
return $sum;
}
Řádky uvnitř foreach vypíše konzole pod nálezem cyklu jako Then also: posunou se jen proto, že
se posune cyklus, a samostatný nález to není.
indentation.unit
Every line indented by the construct it continues, one level per nesting, the level being this unit; under keep a
line stays where it is.
tab: one tab per level4 spaces: four spaces per level2 spaces: two spaces per levelkeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs '4 spaces', psr12 '4 spaces',
nette tab, symfony '4 spaces', laravel '4 spaces' · pokrývá
array_indentation, indentation_type, no_leading_namespace_whitespace,
statement_indentation, Generic.WhiteSpace.DisallowSpaceIndent,
Generic.WhiteSpace.DisallowTabIndent, Generic.WhiteSpace.ScopeIndent
indentation.tabWidth
How many columns a tab counts for in the width of a line.
- počet od 1 do 8
Výchozí 4 · standardy: perCs 4, psr12 4, nette 4,
symfony 4, laravel 4
indentation.singleLevel
A line steps in by one level at most, and only to a level something opened, a comment spanning several lines included.
required: always therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
keep, symfony keep, laravel keep
indentation.singleLevelInComments
Whether a single-line comment standing on a line of its own steps in as a line of code does.
yes, nebono
Výchozí no · standardy: perCs no, psr12 no, nette
no, symfony no, laravel no
indentation.binaryOperator
The levels a line opened by &&, +, . steps in by from the start of its
expression, 1 at least where the expression shares its first line.
- počet od 0 do 1
keep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs 0, psr12 0, nette
0, symfony keep, laravel keep
indentation.ternary
The levels ? and : opening a line step in by.
- počet od 0 do 1
keep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs 1, psr12 1, nette
1, symfony 1, laravel keep
indentation.chain
Where the links of a chain spread over lines stand.
flat: every link one level below the startnested: a link one level deeper or shallower than the link before itkeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs flat, psr12 flat, nette
nested, symfony keep, laravel flat · pokrývá
method_chaining_indentation, PEAR.WhiteSpace.ObjectOperatorIndent
Hodnota nested je volba Nette Coding Standardu: článek se smí odsadit o úroveň hlouběji nebo mělčeji než
článek před ním, takže řetěz, který na chvíli pracuje s jiným objektem, to může ukázat odsazením. Hlouběji než
o úroveň ale ne:
indentation:
chain: nested
$form->addText('name')
->setRequired()
->addCondition($form::Filled)
->addRule($form::MaxLength, null, 100)
->endCondition();
$users = $db->table('users')
->where('active', true); // Expected the chained call indented by 1 tab, 3 tabs found.
$form->addText('name')
->setRequired()
->addCondition($form::Filled)
->addRule($form::MaxLength, null, 100)
->endCondition();
$users = $db->table('users')
->where('active', true);
S hodnotou flat by se článek addRule() vrátil na úroveň ostatních.
indentation.switchCase
The levels case steps in by from switch.
- počet od 0 do 1
keep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs 1, psr12 1, nette
1, symfony 1, laravel 1 ·
pokrývá PSR2.ControlStructures.SwitchDeclaration
indentation.heredoc
The levels the body and the closing marker of a heredoc or nowdoc step in by from the line the heredoc starts on,
0 at its level and 1 one level deeper, lines of the body indented further keeping their extra
indentation.
- počet od 0 do 1
keep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs 1, psr12 keep, nette
1, symfony keep, laravel keep · pokrývá heredoc_indentation
indentation.commentLines
The inner lines of a comment on several lines whose first line stands where it should; a comment moved with its line takes its inner lines along under any value.
aligned: every inner line in the column of the first, the stars of a doc comment one space in from its openingkeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs aligned, psr12 aligned, nette
aligned, symfony aligned, laravel aligned