Prettier inserts a syntax error when there is a comment after an if statement
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Bắt đầu với bản tái hiện PHP tối giản từ issue bằng cách sử dụng trình định dạng dòng lệnh, sau đó so sánh đầu ra của nó với công cụ báo cáo hoặc playground. Truy vết đường dẫn định dạng khối PHP và chú thích ở cuối chịu trách nhiệm chèn thẻ mở bổ sung. Được xem là hoàn tất khi trường hợp comment-after-if được định dạng mà không có \u003c?php thừa và vẫn hợp lệ về cú pháp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- PHP
- Star
- 1.9k
- Fork
- 139
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của prettier/plugin-php
-
PHP 8.3 not allowed in options? Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
prettier/plugin-php#2416 · 2 bình luận · 6 reaction ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
prettier/plugin-php#2498 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
prettier/plugin-php#2495 ·
-
strange format issue Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
prettier/plugin-php#2490 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
prettier/plugin-php#2455 ·
Tất cả issue của prettier/plugin-php
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
getgrav/grav-plugin-api#45 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
RSS-Bridge/rss-bridge#5098 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
phingofficial/phing#2025 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
silverstripe/developer-docs#911 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100