I use the Flex Builder plug-in on top of Eclipse for Flex development . When it comes to coding in Flex, I often find myself missing all of those subtle but priceless options that Eclipse’s Java editor has, like the code formatting, code templates, commenting style or the all-mighty “Save Actions” option which automatically performs specific actions whenever you save your code.

I’ve recently started working on a project with an existing codebase, out of which 90% is Flex code. Facing the possibility of applying our team’s coding guidelines to countless lines of Flex code that I would have to modify, I turned to my browser and began a frantic search for something that would help. I came across a small project aiming to provide exactly what I needed : Flex formatting options. The project is called Flex Formatter and it can be found at  http://sourceforge.net/projects/flexformatter/ on good ol’ Sourceforge. It provides a set of formatting options for ActionScript and MXML code which may cover some of the common needs of any Flex developer out there.

To install it, I downloaded the latest version (0.6.7 at the time of this writing) from Sourceforge, in the form of a jar file. I copied the jar in Eclipse’s plugins folder and restarted Eclipse.

After restarting Eclipse, a new item called Flex Formatting appeared in Eclipse’s Preferences window, with options for ActionScript and MXML indenting and code formatting. I found particularly useful the indentation and the text wrapping options. Once I decided on the rules I wanted, I clicked ‘Apply’ to save my changes. Back in Eclipse’s main toolbar, 2 new buttons have appeared : Format Flex code (selected lines) and Indent Flex code (selected lines). The first will apply the rules you have specified on any Flex code selection (including indentation), while the second button will only properly indent the Flex code selection.

Another interesting option of this small tool is the possibility to export the rules to a file and import them later. This can be done from the same Flex Formatting item in Eclipse’s Preferences window. Exporting & importing make it easier for team members to share their coding style options. One team member could create the rules, export them to a file and put the file on a versioning server. The rest of the team could then retrieve the file from the versioning server and import it in Eclipse.

The formatter is far from complete. In its current version (0.6.7), it lacks some options like performing the formatting on save and it could also do with a more fine-grained set of formatting options. However, after just a couple of days of using it, this tool has saved me a lot of time and energy and I think it is definitely worth using it and I would recommend it to any Flex developer. Just try it, it won’t bite. It just flexes.

Tagged with:
 

5 Responses to A Flex formatter

  1. aiachim says:

    Hi Margelatu,

    I find your post very useful.

    Regards,

  2. Cornel says:

    Hi,

    You can also use IntelliJ in order to format the AS/MXML files. Does not work 100% but is ok

  3. Mario says:

    Hi,

    I am using this formatter for quite a while. The best thing is, that you can post bugs, and the developer is faster than speed of light :)

    • margelatu says:

      Our team is actually using it as a standard. We defined a set of formatting rules which we exported into a file that we share via version control. Each member of the team has the plug-in installed and imports the formatting rules from the shared file.

  4. helsinki says:

    I use this just for a quick cleanup of a file or finding source code online I want to use.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">