Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite indent on-save and overall issues with indentation. #122

Open
HenrijsS opened this issue Sep 19, 2023 · 8 comments
Open

Infinite indent on-save and overall issues with indentation. #122

HenrijsS opened this issue Sep 19, 2023 · 8 comments

Comments

@HenrijsS
Copy link

HenrijsS commented Sep 19, 2023

So I wanted to switch from PHP Intelephense to phpfmt and it works on just regular PHP files (Ex., laravel controllers), but when I mix HTML in them, hell breaks loose.

See this attached video. It starts with the formatting that intelephense has, but when I save, php blocks are indented at the start and the HTML in the while is just infinitely indenting:

https://share.cleanshot.com/vlw4ftlb

Here's my phpfmt config:

{
    "phpfmt.passes": [
        "ConvertOpenTagWithEcho",
	"DoubleToSingleQuote",
	"AlignPHPCode"
    ],
    "phpfmt.psr2": false
}

EDIT:

It works perfectly fine when I use curly braces instead of endif; and enwhile;

@driade
Copy link

driade commented Sep 20, 2023

Hi @HenrijsS good morning. Could you please share the html snippet so I can reproduce the bug?

@HenrijsS
Copy link
Author

<?php get_header(); ?>

<div class="container my-8 mx-auto flex flex-col">
    <?php if (have_posts()) : ?>
        <?php
        while (have_posts()) :
            the_post();
        ?>
            <div class="section-title mb-8">
                <h1><?= get_the_title(); ?></h1>
            </div>
            <?php get_template_part('template-parts/content', 'tribe_event_series'); ?>

        <?php endwhile; ?>

    <?php endif; ?>

</div>

<?php
get_footer();

@driade
Copy link

driade commented Sep 21, 2023

Thanks @HenrijsS I'd try to work on this.

@driade
Copy link

driade commented Sep 21, 2023

Hi @HenrijsS It seems the formatter "ReindentColonBlocks", which is active by default, it's causing the problem. Could you please to add it to the "phpfmt.exclude": section of your config as see if it gets better?

Thanks.

@HenrijsS
Copy link
Author

HenrijsS commented Sep 24, 2023

Where could I find the "ReindentColonBlocks"?

CleanShot 2023-09-24 at 15 16 00@2x

EDIT:
Added "phpfmt.exclude": ["ReindentColonBlocks"], to my User json file and it worked.
What does this option do exactly and what do I lose when disabling it?

@driade
Copy link

driade commented Sep 25, 2023

Hmm, I'm sorry I was wrong. It seems that ReindentColonBlocks is one of the "core" transformers and can't be disabled that way.

I'd suggest you to try and directly edit the vscode-phpft file and add the "exclude", but I don't really know how to do that in VSCode. Maybe @kokororin would help.

@HenrijsS
Copy link
Author

No. I disabled it and it worked 😆

I'm just wondering what do I lose when disabling it and if there's a bug overall with this.

@driade
Copy link

driade commented Sep 26, 2023

This formatter seems to scan for "endif", "endforeach", "endwhile" and "endfor" and indent its contents.

So if you use this constructions in your code, yes, you miss that. In my case I don't use that style of coding.

Yes, surely there's a bug in the code, but currently I focus on fixing the easy or the critical ones, as I've somehow "inherited" the package :) The original writers of phpfmt are not here to help!

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants