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

Re: [jslint] Feature request: exit codes

Expand Messages
  • Daniel Cassidy
    2009/1/9 M. Lorton ... Take a look at JSLint4Java, which embeds JSLint and does what you want, as well as being usable as an Ant task. Dan.
    Message 1 of 6 , Jan 13, 2009
    • 0 Attachment
      2009/1/9 M. Lorton <mlorton@...>

      > The current version of JSlint (at least on Rhino) exits with code 1 if
      > it cannot read the file and 0 otherwise. If it instead would exit
      > with 0 only if the file was read AND was free of lint, I could use
      > JSlint in for pre-commit checking under SVN.
      > .
      >

      Take a look at JSLint4Java, which embeds JSLint and does what you want, as
      well as being usable as an Ant task.

      Dan.


      [Non-text portions of this message have been removed]
    • dom@happygiraffe.net
      ... jslint4java works, but it is in need of an update to the latest jslint. Unfortunately I ve left it in a bit of a state. I m hoping to get to working on it
      Message 2 of 6 , Jan 13, 2009
      • 0 Attachment
        On Tue, Jan 13, 2009 at 04:59:14PM +0000, Daniel Cassidy wrote:
        > 2009/1/9 M. Lorton <mlorton@...>
        >
        > > The current version of JSlint (at least on Rhino) exits with code 1 if
        > > it cannot read the file and 0 otherwise. If it instead would exit
        > > with 0 only if the file was read AND was free of lint, I could use
        > > JSlint in for pre-commit checking under SVN.
        > > .
        >
        > Take a look at JSLint4Java, which embeds JSLint and does what you want, as
        > well as being usable as an Ant task.

        jslint4java works, but it is in need of an update to the latest jslint.
        Unfortunately I've left it in a bit of a state. I'm hoping to get to
        working on it soon…

        -Dom
      • Arthur Blake
        Hope this might help someone- I use jslint in my build process from ant as well and it works great (although it s a really old version of jslint...) If you
        Message 3 of 6 , Jan 13, 2009
        • 0 Attachment
          Hope this might help someone- I use jslint in my build process from ant as
          well and it works great (although it's a really old version of jslint...)
          If you care to do some hacking, I'm sure you can get the most recent version
          working.

          Sent to Doug in 2006:
          ---------------------------
          I've written a slightly more sophisticated front end for the rhino version
          of jslint so I can use it within ant or on the command line.
          I'm not sure if you care, but you are welcome to use it, mangle it, post it,
          toss it in the trash, or whatever, if you like.
          Best Wishes.
          Arthur Blake

          //the following code is pasted onto the end of a your original jslint.js
          file into a new file, named jslint_rhino.js

          /*
          07-24-2006 Arthur Blake
          The following section was added so that jslint could be run from rhino (and
          thus ant)
          more easily. It is a little more sophisticated than the original rhino
          version on the jslint.com
          site. It can process multiple files in a single argument (as the
          antprogram may pass arguments in this way)
          and also will display all of the jslint errors found instead of stopping on
          the first error found.
          It also will truncate "evidence" lines that exceed 200 characters so that
          the output won't be overloaded
          when processing JSMin or slightly JSMin processed .js files.
          */

          var i;
          var files = [];
          var numFiles=0;
          var splits;

          // get all files that will be processed from command line into one array
          // this extra processing below is necessary because multiple files can be
          passed in on a single arg.
          // when invoked with the java task inside ant.
          for (i=0; i < arguments.length ; i++) {
          splits = arguments[i].split(' ');
          for (j=0; j < splits.length; j++) {
          files.push(splits[j]);
          numFiles++;
          }
          }

          print ("JSLint! ( http://www.jslint.com) processing " + numFiles + " file" +
          (numFiles!==1?"s":"") + ".");

          for (i=0; i<numFiles; i++) {
          try {
          processFile(i+1,files[i]);
          } catch (e) {
          print("!!!!! jslint threw exception !!!!! " + e);
          }
          }

          function processFile(filenum, file) {
          print();
          var n,e,k;
          var massagedEvidence;
          if (file)
          {
          if (jslint(readFile(file))) {
          print("(" + filenum + " of " + numFiles + ") " + file + ": no js lint
          found!");
          } else {
          n = jslint.errors.length;
          print ("(" + filenum + " of " + numFiles + ") " + file + ": " + n + "
          lint" +(n!==1?"s":"") + " found:");

          for (k=0; k <n; k++) {
          e = jslint.errors[k];
          if (e) {
          print(' ' + (k+1) + '. line ' + (e.line + 1) + ' character ' +
          (e.character + 1) + ': ' + e.reason);
          massagedEvidence= (e.evidence ||
          '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
          if (massagedEvidence.length >200) {
          massagedEvidence = massagedEvidence.slice(0,200) + ' ....
          (truncated) ';
          }
          print(' ' + massagedEvidence);
          } else {
          print(' ' + (k+1) + '. line ' + '?' + ' character ' + '?' + ': '
          + '?');
          print(' ' + '?');
          }
          }
          }
          }
          }


          I pre-compile the .js with the rhino js compiler for speed like so:

          java -cp /rhino/js.jar org.mozilla.javascript.tools.jsc.Main jslint_rhino.js

          And, here is an example of how I invoke it within my ant build script-

          <!--

          Run JSLint against all .js files in the project.

          from http://www.jslint.com:

          JSLint takes a JavaScript source and scans it. If it finds a problem, it
          returns a message
          describing the problem and an approximate location within the source.
          The problem is not
          necessarily an error, although it often is. JSLint looks at some style
          conventions as well
          as structural problems. It does not prove that your program is correct.
          It just provides
          another set of eyes to help spot problems.

          -->
          <target name="javascript.jslint" depends="base.init" description="run all
          .js source code through the jslint javascript verifier to find common
          mistakes and javascript problems">
          <fileset dir="${webapp.dir}" id="javascript.files">
          <include name="**/*.js"/>
          <exclude name="**/processed_js/**"/>
          </fileset>

          <pathconvert pathsep=" " property="javascript.files.list"
          refid="javascript.files"/>

          <!-- run the jslint script as a pre-compiled .js (rhino javascript
          runtime) -->
          <java classname="jslint_rhino">
          <classpath>
          <pathelement path="${scripts.dir}/jslint"/>
          <pathelement location="${scripts.dir}/AntLib/js.jar"/>
          </classpath>
          <arg value="${javascript.files.list}"/>
          </java>
          </target>


          On Tue, Jan 13, 2009 at 12:44 PM, <dom@...> wrote:

          > On Tue, Jan 13, 2009 at 04:59:14PM +0000, Daniel Cassidy wrote:
          > > 2009/1/9 M. Lorton <mlorton@... <mlorton%40yahoo.com>>
          > >
          > > > The current version of JSlint (at least on Rhino) exits with code 1 if
          > > > it cannot read the file and 0 otherwise. If it instead would exit
          > > > with 0 only if the file was read AND was free of lint, I could use
          > > > JSlint in for pre-commit checking under SVN.
          > > > .
          > >
          > > Take a look at JSLint4Java, which embeds JSLint and does what you want,
          > as
          > > well as being usable as an Ant task.
          >
          > jslint4java works, but it is in need of an update to the latest jslint.
          > Unfortunately I've left it in a bit of a state. I'm hoping to get to
          > working on it soon�
          >
          > -Dom
          >
          >


          [Non-text portions of this message have been removed]
        • Daniel Cassidy
          2009/1/13 ... Just copying a newer JSLint into the jar works for me. If you re not finding time to work on jslint4java, would you be
          Message 4 of 6 , Jan 14, 2009
          • 0 Attachment
            2009/1/13 <dom@...>

            > On Tue, Jan 13, 2009 at 04:59:14PM +0000, Daniel Cassidy wrote:
            > > 2009/1/9 M. Lorton <mlorton@... <mlorton%40yahoo.com>>
            > > Take a look at JSLint4Java, which embeds JSLint and does what you want,
            > as
            > > well as being usable as an Ant task.
            >
            > jslint4java works, but it is in need of an update to the latest jslint.
            > Unfortunately I've left it in a bit of a state. I'm hoping to get to
            > working on it soon…
            >
            >
            >
            Just copying a newer JSLint into the jar works for me.

            If you're not finding time to work on jslint4java, would you be interested
            if I offered a hand? I have been using it quite extensively and find it very
            useful -- you may recognise me, I am djcsdy on Google Code.

            Dan.


            [Non-text portions of this message have been removed]
          • dom@happygiraffe.net
            ... Yes, it will do. I haven t advertised that though. :) The only thing is that you won t get access to the new options and so on (via Java). Which is not
            Message 5 of 6 , Jan 15, 2009
            • 0 Attachment
              On Wed, Jan 14, 2009 at 03:43:04PM +0000, Daniel Cassidy wrote:
              > 2009/1/13 <dom@...>
              >
              > > On Tue, Jan 13, 2009 at 04:59:14PM +0000, Daniel Cassidy wrote:
              > > > 2009/1/9 M. Lorton <mlorton@... <mlorton%40yahoo.com>>
              > > > Take a look at JSLint4Java, which embeds JSLint and does what you want,
              > > as
              > > > well as being usable as an Ant task.
              > >
              > > jslint4java works, but it is in need of an update to the latest jslint.
              > > Unfortunately I've left it in a bit of a state. I'm hoping to get to
              > > working on it soon…
              >
              > Just copying a newer JSLint into the jar works for me.

              Yes, it will do. I haven't advertised that though. :)

              The only thing is that you won't get access to the new options and so
              on (via Java). Which is not _that_ big a deal. I would like to provide
              a proper API for doing this however.

              > If you're not finding time to work on jslint4java, would you be interested
              > if I offered a hand? I have been using it quite extensively and find it very
              > useful -- you may recognise me, I am djcsdy on Google Code.

              Feel free to chip in. Probably the best way is to use github though.
              I've moved stuff there as it's far easier to fork off a copy of your own
              and work on it. Sorry, I've been truly bitten by the git bug :)

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