prettier / prettier/plugin-php
Prettier inserts a syntax error when there is a comment after an if statement
まだ誰も着手していません。
- 主要言語
- PHP
- スター
- 1.9k
- フォーク
- 139
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
コマンドラインフォーマッターを使って issue の最小限の PHP 再現から始め、その出力を報告ツールまたは playground と比較します。余分な開始タグの挿入を引き起こしている PHP ブロックと末尾コメントのフォーマット経路を追跡します。comment-after-if のケースが余分な \u003c?php なしでフォーマットされ、構文的に有効なままであれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- php
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100