The webpage above not only explains how to install it on your computer, but at the bottom it explains how to run fixjsstyle which adds almost all missing semicolons as well as some other little things.

As you can see, there is an option to the right: "replace missing semicolons"

Sometimes, that formatter will report "too many errors" and won't do anything. If that is the case, compress your code with this utility: http://refresh-sf.com/yui/ (which will also add semicolons) and then, you can go back to the formatter to uncompress it.

I'm a Flash developer, and I stumbled across this while running a Google search. For fellow AS (a JS cousin) devs, if you're using Adobe Flash Professional (I'm using CS5), when you're editing an actionscript file, click "Tools" and "AutoFormat". The program will take care of the rest.

(Again, this answer is for ActionScript developers, as this is a common issue for us as well. Please don't downvote for irrelevance to JS.)

I think a very important question here is "why?". Seriously, if it's not causing any problems (which it doesn't), then who cares? Yes, I agree that semicolons in Javascript should be required, but they're not, so it's not going to cause any errors. If you feel strongly about this (as I would too), educate your fellow developers about why they should care and solve the problem, rather than employ a hacky script to alter their code.

JavaScript missing semicolons is impossible to unit test accurately and impossible to minify. Developers who do not understand why it is important to add semicolons will not likely understand the implications upon the code of fixing it manually, which is more reason to use a hacky script for prior bad code. I do agree that educating the developers to write the code properly is important, but that does not fix prior bad acts.
–
austin cheneySep 27 '09 at 15:28

1

i completely agree with the reasons to strictly use semicolons, and trust me, I'd be looking to intervene if my co-workers were in the same bad habit of leaving them off. I just don't think it's a good idea to let them continue writing sloppy code and letting a program fix it up for them. Depending how much existing code there is, then yeah I suppose you might require an automated way to solve it, but it's not a long term solution: that's the crux of my argument.
–
nickfSep 28 '09 at 1:20

1

I completely agree that automated semicolon insertion is an extremely bad idea as a standard practice. I would even go so far as to say that developers who are not formally educated or personally versed in writing JavaScript must not be provided the opportunity to write JavaScript unsupervised. Unless better controls are implemented its only a matter of time before client side scripting kills all possibility of the web as a platform for generating business revenue due to security compromise, collisions, and interoperability problems from difference poor uses in even the same single language.
–
austin cheneyOct 1 '09 at 11:20

Ah ... just discovered YUI compressor has a preserve semicolons options that will actually add the semicolons to the appropriate lines. Then it's just a matter of sending the minified, unmunged version back thru the aptana formatter.