Prettier inserts a syntax error when there is a comment after an if statement
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
Direzione di ricerca
Inizia con la riproduzione PHP minima dell’issue usando il formattatore da riga di comando, quindi confronta il suo output con lo strumento di reporting o il playground. Traccia il percorso di formattazione dei blocchi PHP e dei commenti finali responsabile dell’inserimento del tag di apertura aggiuntivo. Il lavoro è completato quando il caso comment-after-if viene formattato senza un \u003c?php aggiuntivo e rimane sintatticamente valido.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- PHP
- Stelle
- 1.9k
- Fork
- 139
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di prettier/plugin-php
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
prettier/plugin-php#2416 · 2 commenti · 6 reazioni ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 64/100
prettier/plugin-php#2498 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
prettier/plugin-php#2495 ·
-
strange format issue Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
prettier/plugin-php#2490 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
prettier/plugin-php#2455 ·
Tutte le issue di prettier/plugin-php
Issue simili
-
status/awaiting_triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
WordPress/plugin-check#1486 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
az-digital/az_quickstart#6019 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
grokability/snipe-it#19688 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100