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

Rector fixes formatting for php template syntax #8615

Closed
renakdup opened this issue Apr 30, 2024 · 5 comments · Fixed by rectorphp/rector-src#5851
Closed

Rector fixes formatting for php template syntax #8615

renakdup opened this issue Apr 30, 2024 · 5 comments · Fixed by rectorphp/rector-src#5851
Labels

Comments

@renakdup
Copy link

Bug Report

Subject Details
Rector version e.g. v1.0.0 (invoke vendor/bin/rector --version)

I found that Rector tries to fix formatting of PHP Template syntax

Minimal PHP Code Causing Issue

<div class="cocktails-carousel__wrapper animated-block js-swiper-wrapper">
	<div class="cocktails-carousel__info cocktails-carousel__placeholder">
		<?php if ( ! empty( $secondary_title ) ) : ?>
			<h4 class="animated-heading invisible-content"><?php echo $secondary_title; //phpcs:ignore  ?></h4>
		<?php endif; ?>

		<?php if ( ! empty( $title_carousel ) ) : ?>
			<h2 class="animated-heading invisible-content <?php echo esc_attr( $title_class ); ?>"
				><?php echo $title_carousel //phpcs:ignore ?></h2>
		<?php endif; ?>

Expected Behaviour

Expected that Rector would not change it, but now I got next

<div class="cocktails-carousel__wrapper animated-block js-swiper-wrapper">
	<div class="cocktails-carousel__info cocktails-carousel__placeholder">
		<?php if ( ! empty( $secondary_title ) ) : ?>
			<h4 class="animated-heading invisible-content"><?php echo $secondary_title; //phpcs:ignore  ?></h4>
<?php endif; ?>

		<?php if ( ! empty( $title_carousel ) ) : ?>
			<h2 class="animated-heading invisible-content <?php echo esc_attr( $title_class ); ?>"
				><?php echo $title_carousel //phpcs:ignore ?></h2>
		<?php endif; ?>
@renakdup renakdup added the bug label Apr 30, 2024
@samsonasik
Copy link
Member

That's known drawback, see https://github.com/rectorphp/rector?tab=readme-ov-file#known-drawbacks

I tested on https://getrector.com/demo/f2f6777c-c146-4309-b3d4-326f525cc702 and seems no change, It may be due to different tab vs space usage on your own.

you can use coding standard tool after rector to handle that.

@renakdup
Copy link
Author

renakdup commented Apr 30, 2024

I could catch it on another example https://getrector.com/demo/2cf6850a-d099-4fb9-801a-6e22aa793480
.
If we remove the namespace it works fine.

@samsonasik
Copy link
Member

That may can be improved by regex check like in:

Feel free to provide improvement PR, otherwise, you can rely to coding standard tool or skip the file https://getrector.com/documentation/ignoring-rules-or-paths

@renakdup
Copy link
Author

May we open this issue, so that I or somebody else provides this fix in the future? That people see that such kind of problems exist?

@samsonasik
Copy link
Member

The space formatting is already stated as known drawback, not part of "bug", and that is fine as is, and may require refactor once we use php-parser v5.

For templating file, I suggest to run once + fix coding style, then skip at rector.php :)

You can create a PR improvement when you have a chance :)

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