Eclipse JavaScript格式化程序(ctrl-shift-f) [英] Eclipse Javascript formatter (ctrl-shift-f)

查看:141
本文介绍了Eclipse JavaScript格式化程序(ctrl-shift-f)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不喜欢提出这个问题,但我真的一直在寻找一种方法来解决这个问题很长一段时间。

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.

这是一个简单的问题。我一直在使用NetBeans很长一段时间,但是由于几个原因我最近不了解,最近把它切换到了Eclipse。无论如何,我发现JavaScript源格式化行为非常奇怪。

This is a simple question. I have been using NetBeans for a long time, but recently made the switch to Eclipse for a few reasons I won't get into. Anyway, I find the javascript source formatting behavior to be very odd.

以下是我自己格式化的JavaScript代码示例块:

Here is an example block of javascript code that I formatted myself:

function buildDatabase () {
    db.transaction(function (tx) {
        tx.executeSql('DROP TABLE IF EXISTS calendar');
        tx.executeSql('CREATE TABLE IF NOT EXISTS calendar(id UNIQUE, summary, description, location, startdate, enddate)');
    }, function (err) {
        document.querySelector('#debugLog').innerHTML += '<p><code>' + err.message + '</code></p>';
    });
}

非常简单的东西。现在,如果我打了 Ctrl + Shift + F 格式化(因为坦率地说,这个功能是一个巨大的节省时间),因为我可以'现在看起来就像这样:

very simple stuff. Now, if I hit Ctrl+Shift+F to format it (because frankly this feature is a massive time saver) for reasons I can't understand it will now look like this:

function buildDatabase() {
    db
            .transaction(
                    function(tx) {
                        tx.executeSql('DROP TABLE IF EXISTS calendar');
                        tx
                                .executeSql('CREATE TABLE IF NOT EXISTS calendar(id UNIQUE, summary, description, location, startdate, enddate)');
                    },
                    function(err) {
                        document.querySelector('#debugLog').innerHTML += '<p><code>'
                                + err.message + '</code></p>';
                    });
}

为什么要将.transaction移动到新行?它没有接近80的线宽附近。看起来真的很杂乱。它与第二个.executeSql也是一样的,它仍然没有正确包装。这是非常奇怪的。

Why does it want to move .transaction to a new line? It doesn't get anywhere near the line width of 80. It is really messy looking. It is doing the same with the second .executeSql as well, and it still doesn't wrap properly. It's just very odd.

当然,我知道窗口>首选项> JavaScript>代码样式,但无论我做什么在这里修复这个。我希望有更多的Eclipse经验知道出了什么问题。

Now of course I am aware of Window > Preferences > JavaScript > Code Style but no matter what I seem to do in here fixes this. I am hoping someone has more experience with Eclipse to know what is going wrong.

我安装了Android开发工具和PDT。但是,这种行为预先存在这些插件的安装。

I have the Android Dev Tools installed and PDT. However this behavior pre-exists the installation of these plugins.

谢谢,谢谢。

推荐答案

从我的经验来看,这是长时间,不可破坏的线条,导致这个问题。很刺激尝试将长字符串常量(如'CREATE TABLE IF NOT EXISTS calendar(id UNIQUE,summary,description,location,startdate,enddate)')放入一个单独的var中,或者如果它真的错误了,你可以将它分开并且与+连接。

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

我尝试过:

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>';
    });
}

这篇关于Eclipse JavaScript格式化程序(ctrl-shift-f)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆