David asks:
Are there any ColdFusion Code Beautifiers or Formatters you are aware of on RIAForge or within the community?
Now personally I think all ColdFusion code is beautiful, but outside of that - I am unaware of any such tool. I know the old HomeSite+/ColdFusion Studio had code formatters, although I don't remember if there was a ColdFusion one.
Anyone know?
Archived Comments
Homesite+ has Code Sweeper (which I am sure was in all the other versions), but it does NOT beautify the code. I makes it crazy! Don't use it. Even with a lot of configuration, it messes a lot with your tag formatting.
The main problem is that formatting is so subjective. For instance, I do this:
<cfsomething
attribute="value"
attribute="value"
/>
(sub lines would be tabbed in), but other would say that "beautiful" code would have the whole tag on one line. So, how do you standardize this? It's an impossible task unless the configuration of the "beautifier" was quite robust.
Well true - I think we can agree that... well no one agrees on what is beautiful code. ;) But outside of that - I'm still curious as to what tools are out there.
Well, my code is perfect - the reader was curious.
Hmm.... is that thunder?
I have tried HTML Tidy. It has a Eclipse plugin. You can add new-inline-tags, new-blocklevel-tags, and new-blocklevel-tags so it recognizes ColdFusion.
Here are some links.
http://tidy.sourceforge.net/
http://eclipsetidy.sourcefo...
http://jtidy.sourceforge.net/
http://www.w3.org/People/Ra... - sample config file with some cf tags.
I perhaps expose myself to ridicule and shame by even mentioning this in Eclipse-ocratic developer hangout ;), but Dreamweaver has an Apply Source Formatting command which makes for quite nicely formatted, well-organized and readable ColdFusion code.
I am a Dreamweaver guy and i was just using the Source Formatting yesterday to fix some really nasty code i inherited.
It works well. It uses space a lot more then i do. I tend to only use tab's to step code, but it works well and i bet i could make it use tabs if i dug into the preferences.
I tried switching to Eclipse twice and each time i somehow come back to Dreamweaver.
I 2nd the Dreamweaver acknowlegement.
The only real problem that I have with it is that it doesn't outdent the <cfelse> and <cfelseif>.
I've never found an editor that puts your variable names in the proper case depending on how you declared them, the way VB does it based on your DIM stmt.
I think Chad raises a good point. There's really two scenarios in which you need to beautify code:
1. Make sure that YOU, yourself are following your own standards.
2. Clean nasty code that you inherited.
I think performing #1 is inherently hard because it has to be an exact style. However, performing #2 can be much easier as it maybe only needs to get you to a point where you can do #1 manually with little effort. In that case, even the Code Sweeper that comes with Homesite+ /ColdFusion Studio can do a good enough job on #2.
Take for example commenting: I don't like comments that are too long. If a comment line goes past like 80 characters (eyeballing it), I must wrap that comment to another line (and subsequent lines if need be). I doubt there is a beautifier that would handle that rule, however, you could use a program to make all comments ONE line easily, then you could quickly go through and break them up as is needed manually.
My code isn't that bad, really. :|
I've used CF for 7 years. However, I'm a Flex Developer. I completed the CF portion of my current project over the past 13 months.
I've been relatively happy with the formatting on my own project, but I found that there were formats I was happier with later on in my project, and the inconsistency made the code harder to understand as the project grew.
As a Flex Developer, I use Oxygen for Eclipse to format my MXML. Oxygen sorts my attributes, breaks long lines, strips white space, but will preserve line breaks. The consistency within each Flex project is wonderful, as far as the tag-based code is concerned. The indentation and hierarchy of Oxygen explains the hierarchy of my code and makes it easy to identify where each attribute exists or would exist.
I love automation. :)
I'll check out the suggestions above. I use CFEclipse and would prefer to stay in the Eclipse environment.
DB
Years ago, a former boss created a little VB program that would spit out pre-formatted templates, as well asthe ability to beautifying existing code. Sadly, I no longer have access to it.
And yes, I'd prefer to stay within the Eclipse environment.
I would like to see a tool that makes the code we send to the browser look nicer. It would be great if it set code in classes so it was even more portable. Anyone seen anything like that? I have seen one tool that provides it for about everything but CF. We need a regex guru to build the CF version if that is the way we go.
I have been searching for a good CF code formatter for a while, as my CF code is Uuuuggggly. Well Ok, its not that bad. But, I can tell who wrote it, our college intern or me. (in his programming classes he gets marked down for each extra space or missing space with his code formatting)
I too would vote for Dreamweavers format code feature as the best CF code formatter. I have even been known to open a file in DW just to use the format code feature, save file, close DW and then go back to CFeclipse.
I would love to see Mark Drew, or another member of the CFeclipse team, and the Adobe guys get together and build a plug-in (like the RDS thing) for CF code formatting.
I use DW's formatter also. I'm obsessive about formatted code, it's probably the one reason I still use DW instead of CFEclipse.
I manually edited cfcomponent.vtm and cffunction.vtm like so:
Second line of cffunction.vtm:
tagformat indentcontents="yes" formatcontents="yes" nlbeforetag="2" nlbeforecontents="1" nlaftercontents="1" nlaftertag="2"/
Second line of cfcomponent.vtm:
tagformat nlbeforetag="1" nlaftertag="2" indentcontents="yes"/
(I left out the opening and closing angle brackets to avoid issues with posting this)
This formats the cfcs with empty lines between each cffunction for readability.
@John Farrar: You could check out Apache::Tidy, or some such Web server plugin. http://www.perlmonks.org/?n...
I wanted to add a link to some code Ben wrote. It looks like it could be used as a starting point for a CF Formatter, in the event any RegEx fanatic needs a building-block/starting-point.
http://www.bennadel.com/ind...
Joel Cox rocks!!!
By modifying the VTM files, I have endless control over the formatting of my CF in DW.
I couldn't be happier (until my DW trial expires ;) )
VTM files, eh?
Have you found a way to outdent the <cfelse> and <cfelseif>?
Using Eclipse (extraordinarily faster than DW) and the built in Find and Replace, I've been able to replace all double spaces with a single space. The Find and Replace can be done (as you all know) for an entire directory.
I've been able to bastardize the Dreamweaver VTM files to give a decent degree of formatting.
But, as Phillip points out, DW has limitations that make the code hard to read. CF is verbose, but the verbosity doesn't matter to me when the indentation, tabbing, and order of attributes is consistent.
For example
-I prefer all of my cfargument attributes to be in the same order.
- I prefer all of my cfargument attributes to have 3 tabs between attributes.
-I prefer extreme cuddling so I know the execution-order of
Dreamweaver has the following major issues, though:
-DW can't effectively indent the closing CFQuery tag.
-DW can't format my SQL (whose formatting was lost because of a web-based repository we had to use)
-DW can't effectively indent contents within a CFElse of CFElseif tag.
-DW can't handle formatting CFInvoke tags that are formatted with carriage returns.
I paid the $400 for DW. And in the end, I found that I had so many "internal errors", and such terrible lag issues, that it wasn't possible to use it effectively for formatting on a large scale.
Current assumptions:
The best way to clean up a project is to use the Eclipse RegEx option, which is part of the Find and Replace tool.
A cautionary tale:
Eclipse runs RegEx 100x faster than Dreamweaver. The caveat: CFEclipse has terrible 'back-tracking' with control-Z. My current version of CFEclipse creates its own formatting after about 4-5 backtracks, and I think I'm on 1.3.
If you want the quick and dirty formatting using DW, the vtm file path is below. The trick is to change the metrics from 1 to 2 for the following attributes:
nlbeforetag
nlbeforecontents
nlaftercontents
nlaftertag
Each time you make a change to a .VTM file, you'll need to restart Dreamweaver and run the "Apply Source Formatting" option again.
@ Location of the .vtm files:
C:\Program Files\Adobe\Adobe Dreamweaver CS3\configuration\TagLibraries\CFML
But what is the real solution?
In the long run, the only viable solution is a community project to create a RegEx library for formatting and changing CFML, or a utility that takes CFML and formats it with RegEx.
If your project's formatting is a total loss, like mine was, your best bet is to replace excessive tabs and spaces with RegEx in Eclipse.
ex:
// replaces excessive tabs with a single tab
Find: \t{2,}
Replace:\t
Then, use DW on a case-by-case basis to format the CFML and SQL.
@Phillip,
My RegEx skills are non-existent and DW can't format the contents of the cfelse of cfelseif, even if I add a formatcontents="yes" and identcontents="yes" to the VTM file.
Ultimately, we need a regex that adds a tab to the contents between cfelse/cfelseif and the closing 'cfif'.
I have tried everything folks have listed but the easiest one to use with the best results is the HTML Formatter at:
http://www.logichammer.com/...
You can just drag and drop files or folders on it and it just magically formats everything. Alternatively, you can call it programmatically from your favorite programming language or use windows "Send To" context menu to do it.
I just contacted Matt Pressnall of logichammer / html-formatter. html-formatter is a windows only app, but now after a few people have asked him about building an eclipse plug-in he is going to look into it. Matt will probably hate me for this, but I would encourage anyone reading this to send Matt an email requesting an eclipse plugin version of html-formatter. I really want a good CF code formatter for eclipse.
Opps, I hit post too fast...
You can contact Matt at logichammer / html-formatter at
[email protected]
Hey there --
Released a new version of the HTML Formatter which is very eclipse friendly! Check it out at logichammer.com
I am hoping that if we can format code by attribute order. just like android: http://tools.android.com/re...
I just use my custom code formatter for replacing spaces with tab: http://vikaskanani.wordpres...