Monday, October 8, 2007

Get Ugly Code Automatically with Maven2

The easiest way to piss me off on a Monday is to show me poorly formatted code. Maven2 did this for me "automagically", as the witty people call it. Look at this mess, that you can get by running the simple command mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app:

/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}

What resolution does Maven assume that the average developer is running? Must be about 320x200 to break the line after 20 characters.

Here are the three violations to Sun's code conventions that Maven managed to produce in these few lines:

1. The opening curly brace should go on the same line as the method.
2. A keyword followed by a parenthesis should be separated by a space.
3. A blank space should not be used between a method name and its opening parenthesis.

Thank you for Maven for ruining my Monday.

(Gotcha, super should actually not be followed by a white space, but it looks better with three violations than two, doesn't it.)