Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to custom Eclipse's formatter about jQuery code

This topic is nice, but instead of placing special tag comments everywhere, I look for a solution about jQuery code, more specifically the $ character. Eclipse formatter does not seem to recognize

$.ajax({

and transforms it like this:

$
       .ajax({

Any clues other than changing all $ to jQuery?

edit: I cannot find a minimal example... it seems to happen only on very big functions, with some big comments

Top of one of these big functions

function loadDataArt(id) {
    $.each(id, function(index) {
    $.ajax({

Is transformed into:

function loadDataArt(id) {
    $
        .each(
            id,
            function(index) {
            $
                .ajax({

Tabulations? I'll try to find out more info -_-

edit2: disabling line wrap was the solution.

like image 247
nicolallias Avatar asked May 12 '13 16:05

nicolallias


People also ask

How to format Sts code?

To format your whole script: Open the required file. Go to Source | Format Document or press Ctrl+Shift+F.

How to format Eclipse code?

Eclipse has a default Java code formatting profile, known as Eclipse [built-in], which it uses to format code every time you press the combination keys Ctrl + Shift + F (on Windows) and ⌘ + ⇧ + F (on Mac).

How to format html code in Eclipse?

CTRL + SHIFT + F works fine. Just click on the source codes you want to format and then press CTRL + SHIFT + F .

How do I import code formatter XML into Eclipse?

All you need is to export settings from Eclipse (go to Eclipse's Preferences → Java → Code Style → Formatter and export the settings to an XML file via the Export All button.), and then open IntelliJ IDEA Settings → Code Style → Java, click Manage, and import that XML file by simply clicking Import.


1 Answers

This may be caused by the width of the line. Try changing the amount of characters in a line in Eclipse, it still defaults to 80 which is a throw back to punch card days.

  1. Windows > Preferences > Javascript > Code Style > Formatter > Edit

  2. Change the profile name so it is not the built in Profile

  3. Click the Line Wrapping Tab

  4. Set the Max Line Width

enter image description here

like image 133
Kevin Bowersox Avatar answered Oct 23 '22 21:10

Kevin Bowersox