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

Re: [jslint] Is there a node.js equivalent for wsh.js?

Expand Messages
  • Sean Kelly
    Don t worry about being a JavaScript expert everyone has to start somewhere. I have found it very beneficial reading other peoples code. Look up anything you
    Message 1 of 2 , Mar 30, 2012
    • 0 Attachment
      Don't worry about being a JavaScript expert everyone has to start
      somewhere. I have found it very beneficial reading other peoples code. Look
      up anything you don't understand and make your own decisions about what way
      you would do it if you were to write it yourself. Some people argue that
      you only want to read good code, but I think you can learn a lot from
      reading bad code as well.

      Anyway one of the things I have learned about JSLint from reading the code
      is that you can pass settings to jslint in comments at the beginning of
      your file. For example here is an excerpt from one of mine.

      /*jslint
      nomen: true, indent: 2
      */

      /*globals
      $, document, Addition, Subtraction, Multiplication, Division,
      runAllUnitTests
      */

      /*properties
      allCarry, canDoHorizontal, getLevelDescription, getNextProblem, noCarry,
      renderNextHorizontalProblem,
      renderNextVerticalProblem, setLevel, someCarry,

      _nBlankPosition, _nCarry, _nDigits, _nFind, _nFractionalDigits,
      _oRepeats, _sFractionPartSolution,
      _sFractionalPart1, _sFractionalPart2, _sWholePart1, _sWholePart2,
      _sWholePartSolution,

      html, random, replace, pow, length
      */

      This is kind of cool because I can be explicit about what my external
      dependencies are on a per file basis so I find I actually prefer doing it
      this way. As for the format of your output. If you install the "jslint"
      package using npm (be sure to use the -g flag), the code is placed in your
      AppData on Windows and in the package is a file named reporter.js (mine is
      at C:\Users\seank\AppData\Roaming\npm\node_modules\jslint\lib\reporter.js)
      The file is only 25 or so lines long so I bet you could figure it out. You
      should see a familiar if(e) there and I bet something like the following
      will get you a long way.

      if (e) {
      log('error, line ' + e.line + ', char ' + e.character + ':' + e.reason);
      }

      Reid has the jslint package shared on https://github.com/reid/node-jslint and
      I've been tempted to fork it and see if he'd pull a change from me to make
      the errors more single line parsing friendly. However time is a limiting
      factor for me so maybe this weekend but don't hold your breath.

      SeanK

      On Fri, Mar 30, 2012 at 12:56 PM, cse_html_validator <alhome@...>wrote:

      > **
      >
      >
      > I may want to switch to node.js from WHS, but my setup uses wsh.js. Is
      > there an equivalent that works the same as wsh.js but is for node.js
      > instead of WSH? That would make it a lot easier to switch.
      >
      > For example, I would like the equivalent code for the below that works
      > with node.js. Unfortunately I'm not a "JavaScript expert" so am not sure
      > how to do things like "WScript.Arguments.Named.Exists('options')" in
      > node.js.
      >
      > //----------------------------------------------------------
      >
      > // wsh.js
      > // 2009-03-25
      > // 2011-07-25: Modified for integration with CSE HTML Validator
      >
      > // This is the WSH companion to fulljslint.js.
      > /*
      > Copyright (c) 2002 Douglas Crockford (www.JSLint.com) WSH Edition
      > */
      >
      > (function () {
      > 'use strict';
      > var i, e, arrlen, options = {};
      > if (WScript.Arguments.Named.Exists('options')) {
      > eval('options = ' + WScript.Arguments.Named.Item('options'));
      > } else {
      > options = {indent: 4}; // default if not specified on command line
      > }
      > WScript.StdErr.WriteLine('--JSLint--');
      > if (!JSLINT(WScript.StdIn.ReadAll(), options)) {
      > arrlen = JSLINT.errors.length;
      > for (i = 0; i < arrlen; i++) {
      > e = JSLINT.errors[i];
      > if (e) { WScript.StdErr.WriteLine('error, line ' + ((e.line || -2) + 1) +
      > ', char ' + ((e.character || -2) + 1) + ':' + e.reason); }
      > }
      > WScript.Quit(1);
      > }
      > }());
      >
      >
      >


      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.