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

JSLint for not-quite-JS dialects?

Expand Messages
  • John Hawkinson
    Hi, all. I d like to use JSLint on Adobe s ExtendScript, a JavaScript variant that s used to script Adobe Creative Suite products, like InDesign, PhotoShop,
    Message 1 of 3 , Feb 3, 2011
    View Source
    • 0 Attachment
      Hi, all.

      I'd like to use JSLint on Adobe's ExtendScript, a JavaScript
      variant that's used to script Adobe Creative Suite products,
      like InDesign, PhotoShop, etc. It uses the .jsx file extension.

      One of its quirks is that it has several "preprocesor"-style
      directives that can be incldued in script files, some of which
      are necessary for some scripts (e.g. "#targetengine session").

      I wrote to Douglas Crockford asking for a JSLint option to
      ignore such in JSLint, since otherwise JSLint produces a fatal error.

      He replied saying (quoted w/ permission):
      > No. JSLint is intended to improve code portability. It rejects Microsoft's
      > proprietary traps, as well as Adobe's. # is likely to mean something very
      > different in the next edition.

      Any suggestions on where I can go from here? I don't particularly
      like the idea of maintaining a private fork of JSLint for my own use
      (nor a public one!). "Don't use JSLint on this code" is unpleasant.
      Preprocessing my .jsx files before JSLint is similarly cumbersome.
      I also would like to be able to encourage other Adobe ExtendScript
      developers to use JSLint.

      Are there any good solutions anyone can recommend?


      By way of background, the preprocessor-extensions in ExtendScript are:

      #include file
      #includepath path
      #script name
      #strict on
      #target name
      #targetengine enginename

      and they are documented at
      http://www.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/pdfs/javascript
      _tools_guide_cs3.pdf
      on page 216 and following.

      As of Edition 2011-01-28, JSLint produces:

      Error:
      Problem at line 29 character 2: A css file should begin with @charset 'UTF-8';
      #targetengine session

      Thanks very much for any thoughts.

      --jhawk@...
      John Hawkinson
    • Chris
      ... Hello, I deal with a similar problem. I am responsible for maintaining a large amount of ASP Classic code, much of which is written in JScript. This
      Message 2 of 3 , Feb 4, 2011
      View Source
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, John Hawkinson <jhawk@...> wrote:
        >
        > One of its quirks is that it has several "preprocesor"-style
        > directives that can be incldued in script files, some of which
        > are necessary for some scripts (e.g. "#targetengine session").
        >


        Hello,

        I deal with a similar problem. I am responsible for maintaining a large amount of ASP Classic code, much of which is written in JScript. This involves a few instances of backwards syntax. For instance, to set a session variable, you may say:

        Session("name") = value;

        Or

        Session.Contents("name") = value;

        In normal syntax, it looks like you are attempting to assign a value to the result of a function call, which doesn't make any sense. Yet, this is how it is done.

        I have found that maintaining a private fork of JSLint has been the best answer for this. Doing so allows me to detect the file extension, switch on "ASP" mode, and permit the unusual syntax for the specific objects that require it.

        This process has been much smoother since JSLint now has a repository on GitHub. Keeping up to date with the latest JSLint version has never been easier.

        In your case, adding a quick preprocessing step sounds like your best bet. If you do this, I suggest replacing the initial "#" with a comment, rather than stripping the lines entirely. Doing so would preserve the correct line numbers in JSLint's messages.

        Good luck!

        - Chris
      • John Hawkinson
        Thanks for all the suggestions. I thought I should write back with an update, perhaps useful to others in the same boat. I did indeed end up with
        Message 3 of 3 , Feb 10, 2011
        View Source
        • 0 Attachment
          Thanks for all the suggestions. I thought I should write
          back with an update, perhaps useful to others in the same boat.

          I did indeed end up with quick-and-dirty preprocessor that runs
          JSLint. It's just a quick modification of fulljslint_ui.js. While
          ignoring the #-processor was easiest, I did extend it to process the
          #include directive that we tend to use, for a single include file (and
          fulljslint.html is modified to add that field). Of course, doing it
          this way means JSLint's line number reporting is wrong if you choose
          to use the #include feature. If there was support in jslint for line
          number hinting via comments, that'd be great, but I certainly don't
          expect it.

          Also, there's no great way to shoehorn in preprocessor error messages
          this way. So it is done hackishly.

          Patch follows.

          --jhawk@...
          John Hawkinson
          +1 617 797 0250

          --- fullinit_ui.js 2011/02/05 21:20:14 1.1
          +++ fullinit_ui.js 2011/02/11 05:23:00
          @@ -93,7 +93,41 @@
          show_jslint_control();
          }

          -
          + function extendScript(instr) {
          + var
          + common,
          + input, output, j, m;
          +
          + common = dom.q('#JSLINT_INPUTCOMMON');
          + input = instr.split('\n');
          + output = [];
          + extendScript.prelog = [];
          + for (j=0; j<input.length; j++) {
          + m=input[j].match(/^[\t ]*#include[\t ](.*)/);
          + if (m) {
          + if (m[1] === '"common.jsxinc"') {
          + output.push("// autoinclude: "+m[1]);
          + output.push(common.getValue());
          + output.push("// end autoinclude");
          + extendScript.prelog.push(
          + "#included common.jsxinc");
          + } else {
          + extendScript.prelog.push(
          + "ignoring #include of " + m[1]);
          + }
          + } else {
          + m=input[j].match(/^[\t ]*#/);
          + if (m) {
          + output.push("// autocomment:" + input[j]);
          + extendScript.prelog.push("ignoring "+input[j]);
          + } else {
          + output.push(input[j]);
          + }
          + }
          + }
          + return output.join('\n');
          + }
          +
          // Restore the options from a JSON cookie.

          if (!option || typeof option !== 'object') {
          @@ -123,7 +157,13 @@

          // Call JSLint and display the report.

          - lib.jslint(input.getValue(), option, output);
          + lib.jslint(extendScript(input.getValue()), option, output);
          + if (extendScript.prelog.length) {
          + output.___nodes___[0].innerHTML =
          + extendScript.prelog.join('<br>\n')+
          + output.___nodes___[0].innerHTML;
          + }
          +
          input.select();
          return false;
          });
          --- fulljslint.html 2011/01/30 22:16:00 1.1
          +++ fulljslint.html 2011/02/06 22:24:02
          @@ -139,6 +139,17 @@
          padding: 0.5em;
          width: 100%;"></textarea>
          </p>
          +<p style="background-color: transparent;">
          +<textarea id="JSLINT_INPUTCOMMON" style="
          + border: 2px solid black;
          + color: black;
          + background: goldenrod;
          + font-family: monospace;
          + height: 10lines;
          + overflow: auto;
          + padding: 0.5em;
          + width: 100%;"></textarea>
          +</p>
          <p>
          <input type="button" name="jslint" value="JSLint">
             

          John Hawkinson <jhawk@...> wrote on Fri, 4 Feb 2011
          at 01:13:04 -0500 in <201102040613.p146D4rv023023@...>:

          > Date: Fri, 4 Feb 2011 01:13:04 -0500 (EST)
          > Message-Id: <201102040613.p146D4rv023023@...>
          > To: jslint_com@yahoogroups.com
          > Subject: JSLint for not-quite-JS dialects?
          > From: John Hawkinson <jhawk@...>
          >
          > Hi, all.
          >
          > I'd like to use JSLint on Adobe's ExtendScript, a JavaScript
          > variant that's used to script Adobe Creative Suite products,
          > like InDesign, PhotoShop, etc. It uses the .jsx file extension.
          >
          > One of its quirks is that it has several "preprocesor"-style
          > directives that can be incldued in script files, some of which
          > are necessary for some scripts (e.g. "#targetengine session").
        Your message has been successfully submitted and would be delivered to recipients shortly.