Googles Closure Linter

Style guides are a nice way of maintaining good code, even ColdFusion has one laying around albeit a little neglected nowadays anyone interested in looking over it with me?). Recently Google shared their Javascript coding guide which although is not earth shatteringly new it proves to be a great developer resource especialy if you work in a team of any size.

As a companion they are now making available, publicy, the Closure Linter which is a Js validator used from the terminal/command line that checks that the style guide is being followed.

Installing the program is made foolproof thanks to Pythons "easy_install" and once installed checking your Javascript file is then a simple case of running the following from the Terminal

$ gjslint path/to/my/file.js

I managed to find 114 errors on the first Js file I tried it again which looked something like:

Line 67, E:0131: Single-quoted string preferred over double-quoted string.Line 67, E:0010: (New error) Missing semicolon at end of lineLine 68, E:0005: Illegal tab in whitespace before "}"Line 69, E:0005: Illegal tab in whitespace before "}"Line 69, E:0010: (New error) Missing semicolon at end of lineLine 70, E:0010: (New error) Missing semicolon at end of lineLine 70, E:0300: File does not end with new line. (}))Found 114 errors, including 9 new errors, in 1 files (0 files OK).

Thats actually not the best bit, you can even fix most of the error too by running

fixjsstyle --strict path/to/my/file.js

Regretfully I haven't been able to test this yet due to a bug with the "fixjsstyle" program on the Mac. Once that is resolved though I'll be hopefully be coming back here to share how succesfully it works.