I'm having trouble to get eclipse format my JavaScript well. In this first example, it behaves as expected (not the length of the second url):
Whenever i have a longer url, eclipse goes crazy formatting my code and I get extra padding everywhere, like the example below:
Why does the JavaScript formatter behaving like this, and how do I fix it?
(Just in case: I have not installed any formatter plugin, I just use the default that comes with Eclipse Juno)
The problem can be solved by accessing
Preferences > JavaScript > Code Style > Formatter
These are the steps:
Edit...
.Line Wrapping
tab.Maximum line width
field, enter 9999.Apply
, and Ok
.The problem shows up again for code lines that have more than 9999 characters, but I can live with it.
The long url in the example affects "$.ajax(..." and "$(function()...".
As for "$(function()...", the setting is in Preferences/JavaScript/Code Style/Formatter/Line Wrapping/Function Calls/Arguments. 'Do not wrap' is available.
As for "$.ajax(...", it is similar to 'Qualified invocation' in the Java formatter.(Preferences/Java/Code Style/Formatter/Line Wrapping/Function Calls) Unfortunately, JSDT has no UI for this.(Preferences/JavaScript/Code Style/Formatter/Line Wrapping/Function Calls)
This is a trick for JSDT 1.4.1(WTP R3.4.1).
workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.jsdt.core.prefs
org.eclipse.wst.jsdt.core.formatter.alignment_for_selector_in_method_invocation=16
(since you have your own profile, maybe 1-5 are unnecessary)
This hack will be reverted when you edited formatter settings in preferences. - (To prevent overwriting, all you need to do is export you formatter profile, edit the XML and change the 'org.eclipse.wst.jsdt.core.formatter.alignment_for_selector_in_method_invocation' to 0. Save and reimport again now. This change is permanent.
I don't think this satisfies your needs, it's better to use some other formatter(3rd party plugin), I guess.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With