prettier / prettier/plugin-php

Unstable runs: comment in php tag mixed with html

Abierto
#2,426 1 comentario 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
PHP
Estrellas
1.9k
Forks
139
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

When prettier-php has a comment directly after <php, it reformats the comment on each successive run, resulting in strange behaviour. The most bizarre is copying the line on each successive run of prettier.

note: By stable, I mean the second time you run prettier, it doesn't change the files. If there's a better word for this, I'm happy to change my description.

This bug is captured in a comment on another issue. However, due to this bug breaking a core properties of prettier, stable transformations, I think it's worth its own issue.

similar bugs:

Prettier 3.5.3

PHP Plugin 0.22.4

# Options (if any): None
module.exports = {
	plugins: ["@prettier/plugin-php"],
};

Example 1

Input:

<?php
/**
 * The template for displaying the footer
 */
?>

<div class="footer">
	<?php
	// Footer
	get_template_part("template-parts/footer", "2022"); ?>
</div>

<?php wp_footer(); ?>

Output run 1:

<?php
/**
 * The template for displaying the footer
 */
?>

<div class="footer">
	<?php // Footer
 get_template_part("template-parts/footer", "2022"); ?>
</div>

<?php wp_footer(); ?>

Output run 2:

<?php
/**
 * The template for displaying the footer
 */
?>

<div class="footer">
	<?php // Footer
// Footer
get_template_part("template-parts/footer", "2022"); ?>
</div>

<?php wp_footer(); ?>

Output run 3: each successive run adds a new line with // Footer

Example 2

Input:

		</main><!-- #main -->
	</div><!-- #primary -->

<?php
// get_sidebar();
get_footer();

Output run 1:

		</main><!-- #main -->
	</div><!-- #primary -->

<?php // get_sidebar();
get_footer();

Output run 2:

		</main><!-- #main -->
	</div><!-- #primary -->

<?php // get_sidebar();

get_footer();

Example 3

Input:

			<header class="page-header">
				<h1 class="page-title">
				<?php
				/* translators: %s: search query. */
				printf(
    	esc_html__("Search Results for: %s", "gpo18"),
    	"<span>" . get_search_query() . "</span>"
    ); ?>
				</h1>
			</header><!-- .page-header -->

Output run 1:

			<header class="page-header">
				<h1 class="page-title">
				<?php /* translators: %s: search query. */
    printf(
    	esc_html__("Search Results for: %s", "gpo18"),
    	"<span>" . get_search_query() . "</span>"
    ); ?>
				</h1>
			</header><!-- .page-header -->

Output run 2:

			<header class="page-header">
				<h1 class="page-title">
				 /* translators: %s: search query. */<?php
  	/* translators: %s: search query. */
  	printf(
    	esc_html__("Search Results for: %s", "gpo18"),
    	"<span>" . get_search_query() . "</span>"
    ); ?>
				</h1>
			</header><!-- .page-header -->

Output run 3:

			<header class="page-header">
				<h1 class="page-title">
				 /* translators: %s: search query. */ /* translators: %s: search query. */<?php
  	/* translators: %s: search query. */
  	printf(
     	esc_html__("Search Results for: %s", "gpo18"),
     	"<span>" . get_search_query() . "</span>"
     ); ?>
				</h1>
			</header><!-- .page-header -->

cc: @movva-gpu

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduce los tres ejemplos con Prettier 3.5.3 y PHP Plugin 0.22.4, comenzando con comentarios inmediatamente después de la etiqueta PHP. Rastrea la ruta del formateador que gestiona PHP y HTML mixto, y después añade cobertura de regresión para los ejemplos; se considera terminado cuando el formateo repetido produce una salida idéntica y no se duplican ni se mueven líneas de comentarios.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
php
Área
tooling
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.