BEAUTIFY command breaks the file

braykov

Member³
Hi,
I have created a script that sets a beautifier file and then beautifies a very large number of files. I need to unify the code in our company so we can use version control.
Turns out the BEAUTIFY command breaks the code inside it. Many lines are stuck to the right without adding leading whitespace.
I have further tested trying to beautify a single file. The file is a package .pck, containing the header and the body.
I did two major scenarios. One succeeds and one files.

Successful steps:
1) I dragged the original file to the program window. The file was opened.
2) I clicked the beautifier icon. -> The file gets beautified correctly

Failure steps:
1) I login and open a command window
2) I set a beautifier file: SET BEAUTIFIERRULES 'C:\temp\newBeautifier.br'
3) I execute the command: BEAUTIFY C:\Work\git\db\Packages\myfile.pck
I get the message that the file was beautified. No errors were shown.
The file is broken. I compared it with the correctly formatted file from the first test above - there are a lot of differences.

The same failure occurs if I create a .plsql file and execute it with command-line parameters of PLSQLD.

My conclusion - the BEAUTIFY command and the menu command do not do the same thing. Or I suspect in some way the rules file is not set successfully.

PL/SQL Developer
Version 11.0.4.1774
01.97711 - 13 user license
Service Contract: 01.12.2015
Windows 7 (64-bit) 6.1 Build 7601 (Service Pack 1)

UPDATE:
I did some more testing and I noticed the following:
1) Opening a DOS-style .pck file and saving it after beautifying using the Edit menu results in Unix-style file.
2) Beautifying a DOS-style file using a script with BEAUTIFY command, results in a DOS-style file.
3) I noticed the broken code in the file occurs immediately after the "CREATE OR REPLACE PACKAGE BODY...". The header of the package is beautified properly (only the first empty line before CREATE OR REPLACE BACKAGE... is not removed).
4) I removed the following part from the original file and beautified again (simulated only a header)

Code:
END;
/
CREATE OR REPLACE PACKAGE BODY "IBANK"."FACE" IS

This results in a properly formatted code in the whole file. So, is this a bug? And how quickly can it be solved (or workarounded)?

UPDATE2:
The same problem occurs with CREATE OR REPLACE TYPE and CREATE OR REPLACE TYPE BODY.
 
Last edited:
I need to unify the code in our company so we can use version control.

Out of interest, how does this assist with version control?

In my experience with all PL/SQL code formatters (not just PL/SQL Developer's Beautifier), it's a two-step process:

1. Apply the formatting rules
2. Clean up the mess it made.

I would be extremely nervous of running an entire codebase through any automated formatter.
 
I am nervous :-) And yes, it is a many-step process, but we have to start at some point.
After all code is beautified I can make a baseline for future changes. At this point all developers will start using the same rules file, so Git will hold and show only actually changed code.
I hope there will not be a lot of mess after the bulk formatting. We will apply the changes on one server and test.
 
For example, a developer codes this:

Code:
select 1,
       2,  -- Line 2
       3
from   dual;

Then you beautify it with commas on the left as standard, and you get this:

Code:
select 1
      ,2
      , -- Line 2
       3
from dual;

(or same thing the other way around).

Then there are some constructions that catch out the beautifier - I'm not sure what the exact case is but sometimes nested WITH clauses vanish off a mile to the right. Then the next developer has to fix it before he can do any work on it, and then you have a code diff to explain. Do you let the fixed layout stand or do you tell the developer to re-beautify it prior to checkin? I've worked at sites that had that rule and it ended up being quietly ignored because it required the developer to spend extra time messing up his code to a less readable format.
 
Beautifying the code to a common style is a MUST for us now. One way or another, we are going to do it.
I intend to force the option to automatically apply the beautifier before compile for all developers.
I have recently found there were more bugs with this feature than I expected and I am reporting here all of them. If PLSQLDeveloper does not get fixed we will switch to some other product.
 
Sadly I don't think there is any beautifier on the market that really works. TOAD's one is the closest to being usable out of the major IDEs, though I far prefer PL/SQL Dev in most other respects.
 
Back
Top