vscode-phpfmt
vscode-phpfmt copied to clipboard
Inline php in HTML gets wrongly indented
If I add php code inline which is not sticked against the httml code, it will be wrongfully indented.
This gets indented far away from it's original position.
<input type="checkbox" id="winrm_status" name="winrm_status" <?php echo ($thisChecked ? 'checked' : ''); ?> >
If done like this so the php is attached to the html code, it sticks on it's place
<input type="checkbox" id="winrm_status" name="winrm_status"<?php echo ($thisChecked ? ' checked' : ''); ?> >
Is there an existing option to disable indent on inline html & php?
Maybe due to not having the closing > on the <input> tag is causing the it to bug out?
Maybe due to not having the closing
>on the<input>tag is causing the it to bug out?
Well spotted, but this is unfortunately a typo in the created issue. In code we do have the closing >. Have changed the original post. Thanks!
Looked into it real briefly
maybe adding this line to settings.json
"phpfmt.passes": ["AlignPHPCode",]
This is the full settings I found on the interwebz, hopefull it helps
//phpfmt
"phpfmt.php_bin": "php",
"phpfmt.passes": [
"AlignPHPCode",
"AlignTypeHint",
"AddMissingParentheses",
"ConvertOpenTagWithEcho",
"DocBlockToComment",
"IndentTernaryConditions",
"JoinToImplode",
"PSR2KeywordsLowerCase",
"PSR2LnAfterNamespace",
"PSR2CurlyOpenNextLine",
"PSR2ModifierVisibilityStaticOrder",
"PSR2SingleEmptyLineAndStripClosingTag",
"ReindentSwitchBlocks",
"RemoveUseLeadingSlash",
"StripExtraCommaInArray",
"SpaceBetweenMethods",
],
"phpfmt.exclude": [
"ReindentComments",
"StripNewlineWithinClassBody"
],
"phpfmt.psr2": false,
I use beautify with these in my settings and i dont have to many issues with it

"beautify.language": {
"js": {
"type": [
"javascript",
"json",
"jsonc"
],
"filename": [
".jshintrc",
".jsbeautifyrc"
]
},
"css": [
"css",
"less",
"scss"
],
"html": [
"htm",
"html",
"php"
]
},
Good luck!
Thanks! I had already set the "AlignPHPCode". I finally got a solution. Apparently it's not PHPfmt whose doing the wrong indent, It's Code own formatting.
I have set these options, and now it works as expected.
"html.format.wrapAttributes": "auto",
"html.format.wrapLineLength": 0
Well, seems like in some circumstancesthe code still gets wrongly indented. When I remove AlignPHPCode from the passes, the problem is gone. So AlignPHPCode needs to be adjusted so it excludes lines where are on the same row.
try "Format HTML in PHP " after "phpfmt". then wrong spaces removed.
Adding another case; take this input
<ol class="product-items <?php echo /* @noEscape */$type?>">
It will get formatted to
<ol class="product-items<?php echo /* @noEscape */$type ?>">
Note the space after product-items disappeared
Updated to the latest version, but my use case is not resolved. It's partially the reason I wanted ignores in the first place.