This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 179184 - HTML + PHP Format wrecks code
Summary: HTML + PHP Format wrecks code
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 normal with 3 votes (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-04 06:21 UTC by caesar2k
Modified: 2010-11-03 13:35 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Code format mess (314.26 KB, image/jpeg)
2010-01-04 06:21 UTC, caesar2k
Details
Image showing issue (83.15 KB, image/png)
2010-06-25 19:12 UTC, dave7003
Details
Formatted with 6.8. (12.24 KB, image/png)
2010-07-02 17:19 UTC, mcrawford620
Details
Same code, formatted with 6.9. (72.62 KB, image/png)
2010-07-02 17:19 UTC, mcrawford620
Details
test case PHP/HTML (676 bytes, application/octet-stream)
2010-08-17 17:16 UTC, mcrawford620
Details
new test case PHP/HTML (243 bytes, text/plain)
2010-10-29 19:37 UTC, mcrawford620
Details

Note You need to log in before you can comment on or make changes to this bug.
Description caesar2k 2010-01-04 06:21:50 UTC
Created attachment 93042 [details]
Code format mess

Netbeans have this annoying behavior since 6.1 (when I started using it). The code formatter is simply useless. I've read people here pointing to the Zend Framework Code Standards, and I think that is the time to take action. 
In the screenshot you can see the code after the "format". It hurts my eye, a lot. I'm having to manually indent everything, again. Most of the times while working with views that mix HTML and PHP, the result is this mess, so, since version 6.1, I'm avoiding using format function for PHP, even though it works properly for Javascript, go figure.

Really, why don't just copy the Zend Studio formatting, it's open source you know (Eclipse).
Comment 1 Tomasz Slota 2010-02-04 10:12:03 UTC
ppisl is the new owner of formatting/indentation area
Comment 2 Petr Pisl 2010-05-06 15:32:33 UTC
Could you please try with the new formatter in NB 6.9. I have did many fixes and improvements in this area. I'm closing it now, but please reopen and attach the fil (if it's possible), where the formatter doesn't work correctly.
Comment 3 dave7003 2010-06-25 19:12:25 UTC
Created attachment 100427 [details]
Image showing issue

Shows how td tags continue to indent between each new php tag.
Comment 4 dave7003 2010-06-25 19:24:44 UTC
This issue still exists. I am using IDE 6.9 PHP build on Ubuntu 10.04 and have seen same issue as previously noted and I have also provided screenshot from my code. PHP or HTML by themselves on a page indent perfectly as defined, but when mixed the indent starts to increase at some point in page. It starts out OK, but then eventually something causes it to break.

I also noted after removing spaces from code, 10 new spaces appear at end of some HTML lines. It will increase each time you press Alt-Shift-F key.

I don't recall seeing these issues when using 6.5 or 6.8.
Comment 5 mcrawford620 2010-07-02 17:19:00 UTC
Created attachment 100575 [details]
Formatted with 6.8.
Comment 6 mcrawford620 2010-07-02 17:19:38 UTC
Created attachment 100576 [details]
Same code, formatted with 6.9.

Agree that it's a new problem introduced with 6.9.
Comment 7 Petr Pisl 2010-08-17 13:05:09 UTC
Yesterday I have done probably the biggest changes in html + php formatting since NB 6.9. Could you please check, whether is sufficient for you. I'm closing now the issue as fixed, feel free to reopen, if you find a case when it doesn't work.
Comment 8 mcrawford620 2010-08-17 17:16:09 UTC
Created attachment 101461 [details]
test case PHP/HTML

Thanks for the new work. 

Attaching test case: When code is first formatted, PHP code near line 18 moves all the way to the left. This looks wrong as it should be indented at least as far as the tr tags.

Then, if code is formatted again, the PHP code near line 18 gets indented to near the tr tags, which is better. But the opening form tag does not match up with the closing form tag, and this mistake continues on through the table and tr tags.

Also, the PHP code near line 25 gets indented too much, even after the second pass of formatting. The PHP tags themselves are correct at two tabs, but the "if" statement is indented 5 tabs.

(In 6.8, it didn't always put a line break after the opening PHP tag, such as on line 25, but now it seems to always put one in. I can understand if that's a stylistic choice, but personally I liked it better without a forced line break. The line break should be optional.)
Comment 9 mcrawford620 2010-10-01 16:39:59 UTC
I just saw that this issue was still marked as Resolved Fixed. I neglected to re-open it when I left my last comment and test case on Aug 17. I hope some more work can still be done on this. Thanks.
Comment 10 Petr Pisl 2010-10-05 14:42:03 UTC
I have made more fixes in this area. The last example should be fine now. Could you check it. Please, reopen, if you find another case, where it doesn't work.

In NB 6.8 the formatter basically didn't touch the lines, it was just an indenter.

Thanks, for your testing.
Comment 11 mcrawford620 2010-10-29 19:36:55 UTC
Thanks for your work, definitely working better. I'm attaching another test case to show similar problem behavior.

The code as attached is formatted correctly. Then when auto-formatted, lines 12-14 are improperly indented.

I don't know if this helps, but the "print_r" statement on line 16 seems to be causing the problem -- if you remove that line, then the formatting works correctly.

Also, if you remove lines 6 and 8 (the foreach and endforeach), the problem still exists but is lessened by one tab stop; i.e., the closing tags are still indented too much, but not as much as before.
Comment 12 mcrawford620 2010-10-29 19:37:57 UTC
Created attachment 102714 [details]
new test case PHP/HTML
Comment 13 Petr Pisl 2010-11-02 11:03:04 UTC
I'm not sure whether you are writing  about the last attached example, because the print_r function is on the line 14 not 16. The attached example seems to be formatted correctly. I have create another test for it and result of the formatting is here: http://hg.netbeans.org/web-main/file/deb5522cb651/php.editor/test/unit/data/testfiles/formatting/html/issue179184_02.php.formatted

So we talk about the same file? Or it works for you in different way?
Comment 14 mcrawford620 2010-11-02 16:02:09 UTC
Ah, my apologies. We were talking about the same file (my mistake on the line number), but I was using NetBeans IDE 6.9.1 (Build 201007282301). I see now from the dates of the comments that your last fix was after that release. I tried it now in the development version and it worked. So it's resolved as far as I can see, but should I leave it to you to change the status?
Comment 15 Petr Pisl 2010-11-03 13:35:35 UTC
Thanks for your help. I'm closing this bug as fixed now. Please if you find another case, when the formatter doesn't work as you expected file  a new bug for the specific case.