[英]Eclipse JavaScript formatter crazy (i.e: too much padding)
I'm having trouble to get eclipse format my JavaScript well. 我很难将eclipse格式化为我的JavaScript。 In this first example, it behaves as expected (not the length of the second url):
在第一个示例中,它的行为与预期的一样(不是第二个URL的长度):
Whenever i have a longer url, eclipse goes crazy formatting my code and I get extra padding everywhere, like the example below: 每当我有一个更长的网址时,eclipse会疯狂地格式化我的代码,并且我到处都得到额外的填充,如下例所示:
Why does the JavaScript formatter behaving like this, and how do I fix it? 为什么JavaScript格式化程序的行为如此,我该如何解决?
(Just in case: I have not installed any formatter plugin, I just use the default that comes with Eclipse Juno) (以防万一:我没有安装任何格式化程序插件,我只使用Eclipse Juno附带的默认设置)
The problem can be solved by accessing 这个问题可以通过访问来解决
Preferences > JavaScript > Code Style > Formatter
These are the steps: 这些是步骤:
Edit...
. Edit...
,请单击Edit...
Line Wrapping
tab. Line Wrapping
选项卡。 Maximum line width
field, enter 9999 . Maximum line width
字段中,输入9999 。 Apply
, and Ok
. Apply
,然后单击Ok
。 The problem shows up again for code lines that have more than 9999 characters, but I can live with it. 对于具有超过9999个字符的代码行,问题再次出现,但我可以忍受它。
The long url in the example affects "$.ajax(..." and "$(function()...". 示例中的长URL会影响“$ .ajax(...”和“$(function()...”)。
As for "$(function()...", the setting is in Preferences/JavaScript/Code Style/Formatter/Line Wrapping/Function Calls/Arguments. 'Do not wrap' is available. 至于“$(function()...”,设置在Preferences / JavaScript / Code Style / Formatter / Line Wrapping / Function Calls / Arguments中。'do wrap'可用。
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) 至于“$ .ajax(...”,它类似于Java格式化程序中的'合格调用'。(首选项/ Java /代码样式/格式化程序/行包装/函数调用)不幸的是,JSDT没有这方面的UI。 (首选项/ JavaScript /代码样式/格式化程序/行包装/函数调用)
This is a trick for JSDT 1.4.1(WTP R3.4.1). 这是JSDT 1.4.1(WTP R3.4.1)的一个技巧。
workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.jsdt.core.prefs
org.eclipse.wst.jsdt.core.formatter.alignment_for_selector_in_method_invocation=16
(since you have your own profile, maybe 1-5 are unnecessary) (因为你有自己的个人资料,可能不需要1-5个)
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.
- (为了防止覆盖,您需要做的就是导出格式化程序配置文件,编辑XML并将'org.eclipse.wst.jsdt.core.formatter.alignment_for_selector_in_method_invocation'更改为0.现在再次保存并重新导入。此更改是常驻。
I don't think this satisfies your needs, it's better to use some other formatter(3rd party plugin), I guess. 我认为这不能满足你的需求,最好使用其他格式化程序(第三方插件)。
I've found a temporary solution: 我找到了一个临时解决方案:
Go to Window -> Preferences -> JavaScript -> Code Style -> Formatter
转到
Window -> Preferences -> JavaScript -> Code Style -> Formatter
Set the active profile to JavaScript conventions. 将活动配置文件设置为JavaScript约定。
Click Edit 单击编辑
In the Indentation
tab, set Tab policy
to Spaces only .
在“
Indentation
选项卡中,将“ Tab policy
设置为“ 仅限空格” 。
Set both Indentation size
and Tab size
to 3 .
将
Indentation size
和Tab size
都设置为3 。
As you cannot override the default profiles, change the profile name and save. 由于无法覆盖默认配置文件,请更改配置文件名称并保存。
Press Ctrl + Shift + F and enjoy. 按Ctrl + Shift + F并欣赏。
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. 注意:我不喜欢有3个空格,我宁愿选择我的旧4空格,但这是一个临时解决方案,直到有人找到更好的解决方法。 I just felt like sharing.
我只想分享。
Here's what I found: in "Line Wrapping > Function Calls" set "Indentation Policy" at the bottom to "Indent by one". 以下是我发现的内容:在“Line Wrapping> Function Calls”中,将“Indentation Policy”设置为“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.
我没有用你的确切代码尝试过,但我看到了类似的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.