Eclipse Javascript formatter (ctrl-shift-f)

前端 未结 5 1695
北恋
北恋 2021-02-02 09:38

I don\'t like asking this question but I have honestly been looking for a way to figure this out for a very long time.

This is a simple question. I have been using NetBe

相关标签:
5条回答
  • 2021-02-02 10:16

    I have found this as well, and it is one of the main reasons why I largely moved back to NetBeans.

    I don't have the solution, but I can give you some general tips that worked for me, at least to some extend.

    1. Instead of brackets like this: }); try to put each one on a new line.
    2. Instead of parsing parameters like this:

      calendar(id UNIQUE, summary, description, location, startdate, enddate)

    maybe try

    calendar(id 
    UNIQUE, 
    summary, 
    description, 
    location, 
    startdate, 
    enddate)
    

       3. Lastly you could try to put the + on a new line when concatenating strings.

    Like I said, I know this does not solve your problem, but I figured at least it might help you until a better solution comes along.

    Best of luck.

    0 讨论(0)
  • 2021-02-02 10:23

    From my experience, it is the long, unbreakable lines that cause this problem. Very irritating. Try putting the long string constants (like "'CREATE TABLE IF NOT EXISTS calendar(id UNIQUE, summary, description, location, startdate, enddate)'") into a separate var, or if it really bugs you, you could break it apart and concat with +.

    I tried this:

    function buildDatabase() {
        var sql1 = 'CREATE TABLE IF NOT EXISTS calendar(id UNIQUE, summary, description, location, startdate, enddate)';
    
        db.transaction(function(tx) {
            tx.executeSql('DROP TABLE IF EXISTS calendar');
            tx.executeSql(sql1);
        }, function(err) {
            document.querySelector('#debugLog').innerHTML += '<p><code>'
                + err.message + '</code></p>';
        });
    }
    
    0 讨论(0)
  • 2021-02-02 10:26

    Preferences > JavaScript > Code Style > Formatter > Line Wrapping (tab)

    uncheck >> prefer wrapping outer expressions (keep nested expression on one line)

    0 讨论(0)
  • 2021-02-02 10:29

    The problem can be solved by accessing

    Preferences > JavaScript > Code Style > Formatter
    

    Proceed:

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

    0 讨论(0)
  • 2021-02-02 10:33

    I had the same problem. What I did was install the Aptana Studio Plugin and start using the JavaScript Editor it comes with. It is a lot nicer than the one that comes with WTP.

    0 讨论(0)
提交回复
热议问题