Eclipse JavaScript格式化程序疯狂(即:填充太多) [英] Eclipse JavaScript formatter crazy (i.e: too much padding)

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

问题描述

我很难将eclipse格式化为我的JavaScript。
在第一个例子中,它的行为符合预期(不是第二个url的长度):

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

每当我有一个更长的网址时,eclipse会疯狂地格式化我的代码,我到处都会得到额外的填充,如下例所示:

Whenever i have a longer url, eclipse goes crazy formatting my code and I get extra padding everywhere, like the example below:

为什么JavaScript格式化程序的行为如此,我该如何解决?

Why does the JavaScript formatter behaving like this, and how do I fix it?

(以防万一:我没有安装任何格式化程序插件,我只使用Eclipse Juno附带的默认值)

(Just in case: I have not installed any formatter plugin, I just use the default that comes with Eclipse Juno)

推荐答案

示例中的长网址影响$ .ajax(...和$(function()...。

The long url in the example affects "$.ajax(..." and "$(function()...".

至于$(function()...,该设置在Preferences / JavaScript / Code Style / Formatter / Line Wrapping / Function Calls / Arguments中。'do wrap'可用。

As for "$(function()...", the setting is in Preferences/JavaScript/Code Style/Formatter/Line Wrapping/Function Calls/Arguments. 'Do not wrap' is available.

至于$ .ajax (...,它类似于'合格的inv Java格式化程序中的ocation'。(首选项/ Java /代码样式/格式化程序/行包装/函数调用)不幸的是,JSDT没有这方面的UI。(首选项/ JavaScript /代码样式/格式化程序/行包装/函数调用)

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)

这是JSDT 1.4.1(WTP R3.4.1)的技巧。

This is a trick for JSDT 1.4.1(WTP R3.4.1).


  1. 启动Eclipse

  2. 打开首选项/ JavaScript /代码样式/格式化程序

  3. 点击新建

  4. 输入根据需要选择配置文件名称,在列表框中选择Eclipse [内置](或JavaScript约定),取消选中立即打开编辑对话框(无需编辑),然后单击确定

  5. 关闭首选项并退出Eclipse

  6. 使用文本编辑器打开以下文件

    workspace / .metadata / .plugins / org。 eclipse.core.runtime / .settings / org.eclipse.wst.jsdt.core.prefs

  7. 查找以下行并将16替换为0
    b $ b org.eclipse.wst.jsdt.core.formatter.alignment_for_selector_in_method_invocation = 16

  8. 保存

  9. 启动Eclipse

  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

(因为你有自己的个人资料,可能是1-5个是不必要的)

(since you have your own profile, maybe 1-5 are unnecessary)

在首选项中编辑格式化程序设置时,将恢复此黑客攻击。 - (为防止覆盖,您需要做的就是导出格式化程序配置文件,编辑XML并将'org.eclipse.wst.jsdt.core.formatter.alignment_for_selector_in_method_invocation'更改为0.现在再次保存并重新导入。此更改是永久。

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格式化程序疯狂(即:填充太多)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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