Eclipse JavaScript formatter crazy (i.e: too much padding)

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 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).

  1. Start Eclipse
  2. Open Preferences/JavaScript/Code Style/Formatter
  3. Click 'New'
  4. Input profile name as you like, select 'Eclipse [built-in]'(or JavaScript Conventions) in listbox, uncheck 'Open the edit dialog now'(no need to edit), and click 'OK'
  5. Close preferences and exit Eclipse
  6. Open following file with a text editor workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.jsdt.core.prefs
  7. Find following line and replace 16 to 0 org.eclipse.wst.jsdt.core.formatter.alignment_for_selector_in_method_invocation=16
  8. Save it
  9. Start Eclipse

(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.

Eclipse JavaScript formatter crazy (i.e: too much padding), The long url in the example affects "$.ajax(" and "$(function()". As for "$(​function()", the setting is in Preferences/JavaScript/Code Style/Formatter/Line  2 Class not found from dependent jar on hot deploy in Eclipse Nov 26 '13 2 Reading XML file from /res/xml using InputStream reader yields invalid characters / encoded data Mar 17 '11 1 Eclipse JavaScript formatter crazy (i.e: too much padding) Apr 26 '18

The problem can be solved by accessing

Preferences > JavaScript > Code Style > Formatter

These are the steps:

  1. Create a new profile (since you cannot edit the builted-in one), if you haven't already, and click Edit....
  2. Open the Line Wrapping tab.
  3. In the Maximum line width field, enter 9999.
  4. Click Apply, and Ok.

The problem shows up again for code lines that have more than 9999 characters, but I can live with it.

Eclipse JavaScript formatter crazy (i.e: too much padding), Eclipse JavaScript formatter crazy (i.e: too much padding). Question. I'm having trouble to get eclipse format my JavaScript well. In this first example, it behaves  6 Eclipse JavaScript formatter crazy (i.e: too much padding) Mar 1 '13 5 Width in percentage not working after jQuery resizing it's parent Mar 16 '13 4 Why can't a long start with zero?

I've found a temporary solution:

  1. Go to Window -> Preferences -> JavaScript -> Code Style -> Formatter

  2. Set the active profile to JavaScript conventions.

  3. Click Edit

  4. In the Indentation tab, set Tab policy to Spaces only.

  5. Set both Indentation size and Tab size to 3.

  6. As you cannot override the default profiles, change the profile name and save.

  7. Press Ctrl+Shift+F and enjoy.

NOTE: I don't like having 3 spaces, I'd rather prefer my good old 4 spaces, but this is a temporary solution, until someone finds a better way to solve this. I just felt like sharing.

Eclipse JavaScript formatter crazy (i.e: too much padding), Длинный URL в примере влияет "$ .ajax (" и "$ (функция() ". Что касается "​$ (функция() ", то настройка находится в настройках/JavaScript/Code  Reduce eclipse tab size with GTK theming. and it has much less padding than the default Gnome3 desaster GTK3 with Eclipse is just a crazy waste of screen

Here's what I found: in "Line Wrapping > Function Calls" set "Indentation Policy" at the bottom to "Indent by one". This creates indentation without the wildly excessive spaces (or tabs). I haven't tried it with your exact code, but I've seen similar issues with mine.

357829 – Javascript formatter seems not to do , Source that will not format, because (I think) it is to large. It also routinely format much larger files, as long as they don't contain syntax it doesn't like. it's whenever you use a method that's also a JavaScript keyword, so,  SAP UI5 run-time component: responsible for execution of Fiori Application, which consists of renderer that converts the app code into browser readable format (i.e HTML5, CSS and JS) Q9. Steps to follow in any programming language to develop an application? Initialization – load necessary dependencies – – Bootstrap in UI5

Auto Indent / Code Formatting / Beautify · Issue #4039 · microsoft , That tab size is honored when I format a .ts or .js file. I don't like the space between function and () (i.e. function (a, b) {. Whenever I paste a piece of code in my SASS files the new extra line is auto formatting jsx file is going crazy, How can I avoid this? Eclipse has this, and Atom to a lesser extent. From User Voice - Auto formatting "It should pick up the type of language based on the choice you made at the bottom right of the screen. If I open a .log file for instance that has xml in it, I would like it to autoformat to the xml setting I changed it too. using the editor.action.format ONLY works based on the file name not what I have told it the contents are.

Developers Who Use Spaces Make More Money Than Those Who , So… this is certainly a surprising result, one that I didn't expect to find when I started exploring the data. And it is impressively robust even when controlling for many If you're weird and prefer a tab to indent by 8, then that's your choice. At Cratejoy, we use spaces in Python and tabs for Javascript and  This is driving me crazy I have a checkox in a fieldset. What I want is to align the checkbox to the left, that it aligns with the left side of the following textfields.

A Prettier JavaScript Formatter, So I set out to make this work, and prettier was born. Ruby developers are embracing static typing and Ein Code, Ein Style formatting. Weird. Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.

Comments
  • Don't put long URLs in the middle of your functions. Define them someplace else.
  • I've already thought of that, but I really don't want to have a bunch of string variables. I know i could make a JSON object, but still, such a big platform as Eclipse shouldn't be behaving like this.
  • Actually i tried that too, but that's actually only postponing the problem to when you have a string of 500 length, then the parentheses will still behave bad.
  • I personally prefer this over an hack, that anyway represents a temporary solution, until when you need to change your formatter settings for any reason. I have edited my answer to put the maximum value admitted by Eclipse: from 500 to 9999.
  • Probably your solution is dependent upon the length of the string. Make the string longer and it will happen again. It has to do with the page margin, if you go beyond it. I fix this by inserting "+" into the center of long string literals. It is a crappy solution but it works.