Spring Cleaning LingPipe with PMD and fixcrlf and emacs

by

I’m so brain dead today that the only activity that seemed possible was cleaning out existing code in some mindless fashion. So, I pulled out a handy mail tip from Otis Gospodnetić and fired up a bunch of tools I could run from Ant.

First off, the core ant task fixcrlf, which allows you to set all end-of-line markers to unix-style line feeds, as well as replacing tabs with a specified number of spaces (4, of course).

Second, time to cleanup emacs so it always does the right thing instead of that pesky tab default. Everyone knows the magic incantation:

(defun java-mode-untabify ()
   (save-excursion
     (goto-char (point-min))
     (if (search-forward "t" nil t)
         (untabify (1- (point)) (point-max))))
   nil)

 (add-hook 'java-mode-hook
           '(lambda ()
              (make-local-variable 'write-contents-hooks)
              (add-hook 'write-contents-hooks 'java-mode-untabify)))

 (add-hook 'html-mode-hook
           '(lambda ()
              (make-local-variable 'write-contents-hooks)
              (add-hook 'write-contents-hooks 'java-mode-untabify)))

 (setq indent-tabs-mode nil)

which I always have to track down off the web. This works in xemacs, anyway.

Next up, the real killer Ant task, PMD, which has all kinds of rules for checking code. I’m using the basic rules (unused variables, empty catch blocks, empty whiles, etc.), the unused code rules, and the imports rules, which find all the places I over-eagerly imported and then never erased. Just download the bin version, unpack it, and copy its lib over to your ant lib and you’re ready to go (you probably won’t need the Xerces and XML-APIs if you’re already running OK with LingPipe).

I can highly recommend all these tools. I hope the 2.4 release of LingPipe’s cleaner than 2.3 in all of the above ways.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s