How to ignore node shebang error in Eclipse?

前端 未结 2 1825
遥遥无期
遥遥无期 2020-12-15 05:11

I am writing some node command line utilities. They all start with the line:

#!/usr/bin/env node

With Eclipse Juno and the Nodeclipse Node

相关标签:
2条回答
  • 2020-12-15 05:13

    Update:

    The issue entered in nodeclipse points out to JSHint issue 66.
    As Paul Verest remarks in his answer (upvoted), this could be as simple as making sure JSHint check the code.
    Since commit 63da9, JSHint knows how to ignore that shebang directive.

    // If the first line is a shebang (#!), remove it and move on.
    // Shebangs are used by Node scripts.
    if (lines[0] && lines[0].substr(0, 2) == '#!')
      lines.shift();
    

    Original answer

    Are you sure '#' is not a valid character (yet used in this question)?

    Double-check the encoding of your node.js file, because if it is UTF-8 with BOM, then the javascript couldn't be launched properly.

    See "What's different between utf-8 and utf-8 without BOM?", and the wikipedia article on shebang (section "Magic number")

    The shebang characters are represented by the same two bytes in extended ASCII encodings, including UTF-8, which is commonly used for scripts and other text files on current Unix-like systems.
    However, UTF-8 files may begin with the optional byte order mark (BOM); if the "exec" function specifically detects the bytes 0x23 0x21, then the presence of the BOM (0xEF 0xBB 0xBF) before the shebang will prevent the script interpreter from being executed.
    Some authorities recommend against using the byte order mark in POSIX (Unix-like) scripts, for this reason and for wider interoperability and philosophical concerns.

    0 讨论(0)
  • 2020-12-15 05:37

    There are 2 option for JavaScript validation in Eclipse:

    • JSDT
    • JSHint (default since Nodeclipse 0.7)

    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:

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

    As @Jess discovered this was error shown by JSDT, not JSHInt, so removing <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)

    UPDATE 3:

    Drawback of <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)

    JSDoc support

    Even click-through to definition click-through to definition

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