RiFi2k / format-html-in-php

Basically this vscode extension uses all your standard configurations for html formatting, and your standard configurations for format on save, etc. It more or less works exactly how vscode should already work as it pertains to HTML in PHP files.
The Unlicense
33 stars 6 forks source link

Wrong formatting #39

Open kanlukasz opened 4 years ago

kanlukasz commented 4 years ago

Describe the bug Wrong formatting

To Reproduce

<?php if ($count_rest == 1) : ?>
    <div class="row row-cols-1 row-cols-md-2 text-center">
    <?php endif; ?>

    <?php the_excerpt(); ?>

    <?php if ($query_blog->current_post + 1 == $query_blog->post_count) : ?>
    </div>
<?php endif; ?>

Expected behavior

<?php if ($count_rest == 1) : ?>
    <div class="row row-cols-1 row-cols-md-2 text-center">
<?php endif; ?>

<?php the_excerpt(); ?>

<?php if ($query_blog->current_post + 1 == $query_blog->post_count) : ?>
    </div>
<?php endif; ?>

Platform and version

Version: 1.44.2 (system setup)
Commit: ff915844119ce9485abfe8aa9076ec76b5300ddd
Date: 2020-04-16T16:36:23.138Z
Electron: 7.1.11
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 10.0.18363
_Addon version: latest_
marelyns commented 4 years ago

Hi! Can you please share your "Format html in php" settings? I have completely other results after formatting.

kanlukasz commented 4 years ago

I don't have any settings - I mean everything is default. After formatting, I have:

<?php if ($count_rest == 1) : ?>
<div class="row row-cols-1 row-cols-md-2 text-center">
    <?php endif; ?>

    <?php the_excerpt(); ?>

    <?php if ($query_blog->current_post + 1 == $query_blog->post_count) : ?>
</div>
<?php endif; ?>

As you can see, the indentation is wrong

Tested on clean VSCode portable version without any additional settings

kanlukasz commented 4 years ago

The sad truth is that there is no perfect formatter for mixed code. PHPStorm can't do that either. Wordpress Coding Standard for PHP Code Sniffer also can't do it

Mixing HTML with PHP is a story that should never have happened anywhere, but as we know Wordpress lives its own life 🤷‍♂️

marelyns commented 4 years ago

I feel your pain. I am slowly giving up about to find a formatter for mixed code. Are you using in parallel a php formatter in vscode?

kanlukasz commented 4 years ago

I'm not sure what you mean by "parallel", anyway I can say that I'm using PHP Intelephense, which has formatter and many other cool features.