ActionScript/Flex/AIR Code Quality Measurement Tools
Posted by Jai on December 7, 2009
From a java developer perspective, you would love to have the similar code quality measurement tools for ActionScript/Flex/Air also but there is hardly any single comparable tool available for this. After a long search and analysis, this is what I have found and here we will have a look at what all these tools and different utilities offer.
In this post we will analyze what different code quality metrics on a general basis we would require for ActionScript/Flex/AIR and what are the different available tools to get such metrics.
Code Quality Metrics
We would like to have the metrics to display different information like:
- Coding Styles: The metrics which tell us the different coding style violations inside the code.
- Coding Standards: The metrics which tell us the different coding standards violations inside the code.
- Project level: Total number of packages, interface, classes etc. , the dependencies between different packages and classes and their linking.
- Class level: Total number of lines of code, number of functions, cyclomatic complexity, dependencies on other classes etc.
- Function level: Total number of lines of code, cyclomatic complexity etc. and coverage tools stating if all the lines of code are fully tested on not.
(This is just on broader level, not covering all the metrics and information which similarly we have for java).
List of Available Tools
The available tools for AcrionScript/Flex/Air code quality measurement are:
- Enterprise IDE Plugin
- Compiler options
(The list may not be complete, but it is as per my best knowledge which I could find around, Feel free to comment and add to it :)).
“Code Coverage Tool for Flex and AIR applications.”
The tool description,
“This project provides code coverage instrumentation, data collection and reporting tools for Adobe Flex and AIR applications.
Flexcover is a code coverage tool for Flex, AIR and AS3. It incorporates a modified version of the AS3 compiler which inserts extra function calls in the code within the SWF or SWC output file. At runtime, these function calls send information on the application’s code coverage to a separate tool; The modified compiler also emits a separate “coverage metadata” file that describes all the possible packages, classes, functions, code blocks and lines in the code, as well as the names of the associated source code files. “
Download: From home page downloads section.
To get started: See wiki page for details, Flexcover Usage Hints
Build-Process: To integrate it with your build process
- To Create EMMA formatted reports, Paul suggests Code Coverage with Flex – creating EMMA formatted reports
- To Convert to Cobertura formatted reports, Brian suggests Converting a FlexCover CVR to Cobertura XML report
For more details, also have a look at Alex’s blog
It uses part of PMD for java,
“FlexPMD is a tool that helps to improve code quality by auditing any AS3/Flex source directory and detecting common bad practices, such as:
* Unused code (functions, variables, constants, etc.)
* Inefficient code (misuse of dynamic filters, heavy constructors, etc.)
* Over-complex code (nested loops, too many conditionals, etc.)
* Over-long code (classes, methods, etc.)
* Incorrect use of the Flex component lifecycle (commitProperties, etc.)”
Downloads: From home page, downloads section
To get started: See How to invoke FlexPMD section to use it from command-line, ant, maven etc.
Violations Viewer: View the generated results using PMD Violations Viewer, and you can also use PMD Hudson plugin to view the results.
It is Copy & Paste Detector,
“FlexCPD is reusing the JavaCPD engine. This project consists in giving a stream of tokens to the CPD engine using the FlexPMD lexer and let the CPD engine detects duplications in those streams.”
Download: From the downloads section.
To get started: You can use either command-line, ant or maven to generate the report, see How to invoke section.
Viewer: You can use Hudson DRY plugin to see the results.
It is, “Visual browser for class and package dependencies in Flex applications”
“ItDepends is a tool for visually exploring the dependencies between classes and packages in an Adobe Flex application, with the aim of making it easy for developers to understand how their application can be made smaller and/or broken up into dynamically loadable modules.”
Download: From downloads section.
Introduction: Why should you use it and what information does it display, see the introduction section.
To get started: To get started, have a look at User’s Guide.
It is, “asDox is a actionscript 3 parser for extracting class/interface/method definitions from source files complete with JavaDoc @tags.”
“asDox is an Actionscript 3 parser written in Python. It is based on qDox for Java. The parser skims the source files only looking for things of interest such as class/interface definitions, import statements, JavaDoc tags and member declarations. The parser ignores things such as actual method implementations to avoid overhead. The end result of the parser is a very simple document model containing enough information to be useful.”
Downloads: See downloads section.
To get started: Have a look at UsingasDox for details.
“The Enterprise IDE Plugin is an architect and developer productivity suite for Adobe(R) Flex (R) Builder 3 designed to simplify and aid the development of Enterprise Applications using Flex Builder 3.”
Features: Have a look at different features list.
Metrics: See what all metrics it provides.
“It analyzes actionscript code and produces some basic stats: number of files, breakdown of lines of code (comments versus whitespace versus real code), and it counts functions and variables. Not really useful for anything in real life, I was just curious how large the Flex SDK was, so I wanted a way to figure that out.”
Not sure how useful it is, but see if it gives you some idea to design or develop your own utility.
“You can generate a report of linker dependencies by setting the link-report compiler option to true. The output of this compiler option is a report that shows linker dependencies in an XML format.”
Examining linker dependencies: Use compiler option to examine the dependencies to reduce the swf file size.
“AIR Link Report visualizer to visualize report generated by above compiler link-report option.”
For more details, see the post AIR Link Report visualizer.
Most of the above tools are still in the very early stages of development and does not much cater the usefulness in the practical scenarios. There is still a long way to go for these tools to be able to the reach the maturity level which we have for java tools. But still something is better than nothing and of-course we are in the right direction at least to have something going on.
I am planning to cover few of these in details covering different pros and cons and how these fit in actual scenarios. In the mean time feel free to share your related experiences.