如何忽略Eclipse中的节点shebang错误? [英] How to ignore node shebang error in Eclipse?
问题描述
我正在编写一些节点命令行实用程序.它们都以以下行开头:
#!/usr/bin/env node
使用Eclipse Juno和Nodeclipse Node.js插件,此行代码将产生错误,如下所示:
好,因此#
在javascript中不是有效的注释字符,但是在Linux/UNIX中,作为文件第一行的 shebang ,它是有效的字符.但是,如何设置Eclipse以忽略此错误?这对我来说是个问题,因为如果您遇到错误,则代码格式化将不起作用.我必须删除该行.按下 CTRL-SHIFT-F 并将行添加回去.
我尝试了很多事情并进行了研究,但找不到答案.
那里有一个重复的问题,在hashbang行上出现eclipse javascript语法错误,但我的问题有更多信息.
好像在 jshint中添加了一些内容,以允许第一行中的字母爆炸 .也许我需要更新我的node-eclipse,或者也许node-eclipse项目需要更新jshint?
- 我的jshint eclipse集成是0.9.6版.
- 我的nodeclipse是0.4.0.20130519 ...
我升级到
- jshint eclipse集成0.9.9.20131029
- nodeclipse 0.7.0.20131101
那没有帮助.
这是我的Eclipse JSHint版本:
感谢您的答复VonC.但是我认为这表明我的文件中没有BOM.还有其他想法吗?
$ od -N 20 -t x1 hello.js
0000000 23 21 2f 75 73 72 2f 62 69 6e 2f 65 6e 76 20 6e
0000020 6f 64 65 0a
0000024
关于下面Paul Verest的回答,我试图关闭JSDT验证,但是我似乎做不到.我未选中启用JavaScript语义验证"(在Eclipse中,请参阅窗口">首选项">"JavaScript">验证器">错误/警告"),但是问题仍然存在.
我现在正在卸载 Eclipse Web Developer Tools 3.4.2 .似乎没有帮助,现在我的CSS和HTML编辑器不见了.现在,我尝试通过遵循以下SO问题中的一些想法来禁用JSDT验证:
这并不容易,但是我最终还是在Eclipse中入侵了.project文件.我有这个: 我删除了jsdt性质,现在shebang行上的错误消失了!我在测试项目和实际项目中都这样做.有效!这实际上非常有用,因为我可以格式化文件,并且现在正在实际运行jshint. 在Eclipse中有两种JavaScript验证选项: 由于配置是按项目存储的,请从用0.7创建的项目中复制.*设置文件,或手动重新配置(只需将.*文件与新创建的项目进行比较).
然后把.jshintrc文件像
https://github.com/Nodeclipse/nodeclipse-1/blob/master/org.nodeclipse.ui/templates/.jshintrc 尝试检查 JSHint选项(如果可能). 请注意,在使用JSHint的情况下,~~此问题成为一般的JSHint问题(与Eclipse或Nodeclipse不相关).
更新: @Jess发现这是JSDT(而不是JSHInt)显示的错误,
因此删除 更新3: 删除 Looks like there was something added to jshint to allow shebangs in the first line. Maybe I need to update my node-eclipse, or maybe the node-eclipse project needs to update jshint? I upgraded to That did not help. Here is my JSHint version in eclipse: Thanks for the answer VonC. But I think this shows that I do not have a BOM in the file. Any other ideas?
With regard to Paul Verest's answer below, I tried to turn off JSDT validation, but I can't seem to do it. I unchecked "Enable JavaScript semantic validation" (In Eclipse, see Window > Preferences > JavaScript > Validator > Errors/Warnings), but the issue remains. I am now uninstalling Eclipse Web Developer Tools 3.4.2. That did not seem to help and now my CSS and HTML editors are gone. Now I have tried to disable JSDT validation by following some of the ideas in this SO question, How do I remove javascript validation from my eclipse project?. So I went into my project properties and went to JavaScript > Validation. I have set everything to "Enabled project specific settings" and unchecked "Errors/Warnings", "JSDOC", etc. Even so, I think validation is still running since the problem persists! My "Builders" Properties only lists the "JSHint Problem Checker" which is enabled. (I am doing all this on a new test project with a hello.js). It was not easy, but I ended up hacking the .project file in Eclipse. I had this: I removed the jsdt nature and now the error on the shebang line is GONE! I did this in my test project and my real project. It worked! This is actually pretty helpful since I can format the file and I'm actually running jshint now. There are 2 option for JavaScript validation in Eclipse: As configration is stored per project, copy .* settings files from project created with 0.7 or re-configure it manually (just compare .* files with newly created project).
Then put .jshintrc file like
https://github.com/Nodeclipse/nodeclipse-1/blob/master/org.nodeclipse.ui/templates/.jshintrc Try to check JSHint options, if it is possible. Note that with JSHint usage, ~~this question becomes general JSHint question (not Eclipse or Nodeclipse related).~~ UPDATE: As @Jess discovered this was error shown by JSDT, not JSHInt,
so removing UPDATE 3: Drawback of Even click-through to definition
这篇关于如何忽略Eclipse中的节点shebang错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!编辑4,答案
<natures>
<nature>org.nodeclipse.ui.NodeNature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
.project
的内容:<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ProjectName</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.eclipsesource.jshint.ui.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.nodeclipse.ui.NodeNature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
将会阻止JSDT显示它(即使从0.7开始就已经关闭了JavaScript语义验证)<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
的缺点将是代码辅助和点击到定义将不起作用(实际上在定义JSDoc的极少数情况下有效,例如eclipse javascript syntax error on hashbang line, but my question has more info.EDIT:
EDIT 2:
$ od -N 20 -t x1 hello.js
0000000 23 21 2f 75 73 72 2f 62 69 6e 2f 65 6e 76 20 6e
0000020 6f 64 65 0a
0000024
EDIT 3:
EDIT 4, THE ANSWER
<natures>
<nature>org.nodeclipse.ui.NodeNature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
.project
content since 0.7 :<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ProjectName</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.eclipsesource.jshint.ui.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.nodeclipse.ui.NodeNature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
will stop JSDT from displaying it (even with JavaScript semantic validation already turned off since 0.7)<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
removed will be that code assist and click-though to definition will not work (It actually works in rare cases when JSDocs are defined e.g. http://www.nodeclipse.org/nodejs/javascript/sources/books/2013/10/22/JSDT-require-JSDoc.html or within 1 .js file)