prettier / prettier/plugin-php

Prettier duplicates a comment and inserts it somewhere else

Abierto
#2,495 0 comentarios 0 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

@prettier/plugin-php v0.25.0
Playground link

Input:

<?php if (have_posts()): ?>

  <p>Content if have posts</p>

  <?php
  /* My comment */
  ?>

  <?php
  // Comment in else
  // Another comment
  // Comment number three
  else: ?>

  <?php if (true): ?>

    <p>This is always true</p>

  <?php endif;
  // end true check
  ?>

<?php endif;
// end have_posts() check
?>

Output:

<?php if (have_posts()): ?>

  <p>Content if have posts</p>

  <?php
  /* My comment */
  ?>

  <?php
  // Comment in else
  // Another comment
  // Comment number three
  // end true check

  else: ?>

  <?php if (true): ?>

    <p>This is always true</p>

  <?php endif;
  // end true check
  ?>

<?php endif;
// end have_posts() check
?>

Notice that the //end true check comment is inserted next to the comments near the else statement.

However, a weirder things happen when I delete the entire /* My comment */ PHP block:

@prettier/plugin-php v0.25.0
Playground link

Input:

<?php if (have_posts()): ?>

  <p>Content if have posts</p>

  <?php
  // Comment in else
  // Another comment
  // Comment number three
  else: ?>

  <?php if (true): ?>

    <p>This is always true</p>

  <?php endif;
  // end true check
  ?>

<?php endif;
// end have_posts() check
?>

Output:

<?php if (have_posts()): ?>

  <p>Content if have posts</p>

  <?php
  // Comment in else
  // Another comment
  // Comment number three
  // end true check
  // Comment in else
  // Another comment
  // Comment number three
  // end true check
  else: ?>

  <?php if (true): ?>

    <p>This is always true</p>

  <?php endif;
  // end true check
  ?>

<?php endif;
// end have_posts() check
?>

Multiple comments get duplicated

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

Empieza reproduciendo el problema a partir de los enlaces de Playground proporcionados y compara la salida del formateador con la entrada, especialmente en torno a los comentarios de PHP cerca de else y endif. Sigue el flujo de gestión de comentarios de plugin-php; se considera terminado cuando los comentarios no se duplican ni se mueven, tanto si el bloque de PHP circundante está presente como si se elimina.

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
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.