This guide explains the example: how to edit the rule in PHPFormatExtension that prevents cuddling of else conditions (i.e., enforces that else must start on a new line after a closing brace).
If you want to change the cuddled else rule just for yourself, you can do so by editing your ruleset XML fileāno need to recompile the extension.
How to Allow Cuddled else Conditions:
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace"/>
else conditions for you, without any need to recompile or change the extension code.else statements is in src/formatter.ts, in the splitCuddledElse function.elseOnNewLine rule is enabled.if (rules.elseOnNewLine) {
lines = splitCuddledElse(lines);
}
splitCuddledElse looks for lines like:
} else {
and splits them into:
}
else {
To change how this rule works (for example, to allow cuddled else conditions):
src/formatter.ts.splitCuddledElse function.else, you can:
splitCuddledElse in the formatter pipeline:
// lines = splitCuddledElse(lines);
Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace.src/rules-xml.ts:
if (hasExcludeName(xml, 'Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace')) {
parsed.elseOnNewLine = true;
}
parsed.elseOnNewLine is set.npm run compile
Summary:
splitCuddledElse function in src/formatter.ts to change the cuddled else rule for everyone.