views:

261

answers:

5

I have used http://jsbeautifier.org/ successfully using Rhino and ant, but the problem is that it is not deterministic. If you run the beautifier twice on a file the result is different from each time, e.g. each pass inserts additional array intendation on some lines.

I have spent a lot of time debugging the code in beautify.js and have made some workarounds for comment handling, but the array indentation bug is annoying.

Is there a correct and properly working JS code formatter anywhere that can be used as part of a source code indentation verification system?

EDIT

I have now tested with preserve-array-formating disabled, and it seems that it solves the problem. Too bad, since preserve-array-formating is quite useful with large array constructs.

A: 

SlickEdit supports code beautification for loads of languages, including JavaScript.

You can even beautify multiple files at once, see

http://mindprod.com/jgloss/slickedit.html#BATCH

Richard Ev
Does it support formatting of multiple files in batch mode? It looks to me as yet another editor.
Ernelli
Yes you can - I've updated my answer
Richard Ev
+1  A: 

I think http://jslint.com/ will do it too.

powtac
A: 

I ususally just do it myself:

new Function(your_code_here).toString()
Avindra Goolcharan
A: 

Jimmys comment regarding the "keep array indentation" option solved the problem.

Ernelli
A: 

Would you please be so kind and just send a message next time you encounter the bug? The contacts are on the bottom of the page. The creator of jsbeautifier.org is a very nice person and reacts to bugs quickly, I know.

Einar Lielmanis
Hi, well first it is only a bug if the intended behavior of jsbeautify is to always produce the same result even if it is ran twice on the same source file. But I'll check with github and forward my findings/corretions to Einar.
Ernelli