Loading ...
Sorry, an error occurred while loading the content.

JSLINT for Windows Script Host - reading from a file

Expand Messages
  • cheesox
    Thanks to Douglas, et al, for JSLINT. I use it on Windows, with cscript.exe, in two ways: - from the command line and in build scripts (makefiles). - and
    Message 1 of 1 , May 20, 2010
    View Source
    • 0 Attachment
      Thanks to Douglas, et al, for JSLINT.

      I use it on Windows, with cscript.exe, in two ways:

      - from the command line and in build scripts (makefiles).
      - and within emacs as I edit .js files.


      I've found it helpful to be able to specify a filename to jslint.js as an argument, rather than sending the content of the source file into jslint.js via STDIN. The real advantage here is that an error message from jslint can specifically identify the name of the .js file that contains the error. It's very helpful in make sessions; makes it easy to grep, and so on.

      Instead of

      cscript.exe jslint-for-wsh.js < Module.js

      I can now *also* use

      cscript.exe jslint-for-wsh.js Module.js

      The change I made allows jslint to continue to use STDIN, if no argument is specified.

      Since I was changing the format of the jslint error message to include the filename, I went one step further to make error messages similar to messages from a {C, Java} compiler. Instead of

      Lint at line 16 character 9: The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.

      I now get:

      Module.js(16,9) JSLINT: The body of a for in .....

      Using this error message format is really nice in emacs, which has a facility to jump to the location of the next error in a particular file, given a list of error messages. Run make, then with one keystroke I have the cursor on the location of the jslint error. Very convenient.

      It also makes it easy to integrate into flymake, if you're familiar with that. Flymake is a minor-mode in emacs that dynamically checks the file being edited for syntax problems, and highlights them as you type. It's a general feature and is intended for use with any language. And syntax checking is JSLINT's raison d'etre, so, it's a nice combination. In action, using flymake with JSLINT in emacs looks like this:

      http://i47.tinypic.com/2mk1eh.jpg

      The change I made to jslint.js is relatively small, and it's confined to the bottom of the jslint-for-wsh module available at http://www.jslint.com/wsh. It checks the WScript.Arguments array, and if an arg is present, the modified jslint-for-wsh assumes.js the arg is the name of a file and tries to read the named file. If no arg is present, it does the same as before: read from STDIN.

      I uploaded the modified file to the files list for the jslint_com group, so anyone can have a look:

      http://tech.groups.yahoo.com/group/jslint_com/files


      -------

      Questions for the group, or Douglas -

      1. regarding the change to allow reading from a file - does this look like a general interest change? I was surprised when searching the group archives to find a message from a year ago on the converse situation in rhino - allowing jslint to read from stdin. ?? I'm a bit puzzled because I thought jslint read *only* from stdin. I must be missing something here.

      2. regarding the change to the error message format, is this friendly? I'm not familiar with the history behind the message format, if there are specific reasons the messages are formatted the way they are. In particular I'm not sure if the jslint message format is designed to mirror popular message formats from lint tools for other languages.

      It occurs to me that the proposed change in message format would make sense, if in the future JSLINT expands to formalize and internationalize the warnings. Instead of just a string, the error or warning would be denoted by a unique error code for each problem, as well as an internationalizable message. Just like a C compiler.

      eg.

      JSL0019: The body of a for in should be wrapped in an if statement

      ----

      I'm new here, so if anyone can answer or guide me, I'd appreciate it.
      And if I'm violating group protocol in some way, my apologies.

      -Dino Chiesa
    Your message has been successfully submitted and would be delivered to recipients shortly.