prettier / prettier/plugin-php
Prettier inserts a syntax error when there is a comment after an if statement
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 is used via command line or via VSCode shortcut, prettier inserts an extra <?php string, creating a syntax error.
Input:
<?php if (true): // example comment
?>
<h1>Heading</h1>
<?php endif; ?>
Output:
<?php if (true):<?php
// example comment
?>
<h1>Heading</h1>
<?php endif; ?>
This behavior, however, is not present within the reporting tool, where the output is as expected: @prettier/plugin-php v0.25.0
Playground link
The .prettierrc file:
{
"useTabs": false,
"tabWidth": 2,
"trailingComma": "es5",
"semi": true,
"singleQuote": true,
"arrowParens": "avoid",
"printWidth": 120,
"plugins": ["@prettier/plugin-php"]
}
- Prettier version: 3.8.3
- PHP Plugin version: 0.25.0
Further information
This issue only happens when a comment is right after an if statement, and the comment is the last thing inside the php block. Here are examples of cases where the code is formatted correctly:
<?php
// example comment
if (true): ?>
<h1>Heading</h1>
<?php endif; ?>
<?php
$test = 'Foo';
if (true):
// example comment
$test = 'Bar'; ?>
<h1>Heading</h1>
<?php
endif; ?>
Those examples are after they were formatted using the command line prettier.
The second example is somewhat questionable, as I suspect the endif statement should not be moved to a new line - before the formatting happened it was in a single line, like in the first example.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la reproducción mínima en PHP del issue usando el formateador de línea de comandos y compara después su salida con la herramienta de informes o el playground. Sigue la ruta de formateo de bloques PHP y comentarios finales responsable de insertar la etiqueta de apertura adicional. Se considera terminado cuando el caso comment-after-if se formatea sin un \u003c?php adicional y sigue siendo sintácticamente válido.
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
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 55/100