skip to Main Content

I’m working with Adobe Extendscript, which == javascript*, and I’m using the Atom JSHint package in Atom. Extendscript is the scripting framework for Adobe apps like Photoshop and After Effects. Adobe do make an IDE but it’s really feeble, so I write with Atom and then switch over to “Extendscript Toolkit” to run my scripts. Anyway…

Adobe lets you use C-style preprocessor directives like #include "myUsefulFunctions.jsx" so that you can keep reusable stuff in libraries like a real programming language.

The problem is that the JSHint linter sees my C-style preprocessor directives at the top of the page, freaks out and gives up. To actually get it to lint my code I have to comment the preprocessor directives out and then remember to uncomment them before I run the code. This means at least 3 or 4 extra keystrokes each time I test, which as you all know is The. Worst. Thing. Ever.

So to save half a dozen keystrokes I’ve been looking into the settings for JSHint. Nothing I’ve found so far seems related. Is there any way of globally getting JSHint to ignore lines like #this, or locally in the file to get it to skip a line or two?

*or is it ===? I’m really confused by JS’s approach to the truth.

3

Answers


  1. Chosen as BEST ANSWER

    I changed the JSHint package that I use, and now there's no need for workarounds.

    For anyone else developing Extendscript in Atom the linter I recommend is this one: Linter-JSHint. It's a plug-in for the Atom Linter package, so you'll need to install that too.

    Then once you've done that use this to ignore a block:

    // Code here will be linted with JSHint.
    /* jshint ignore:start */
    // Code here will be ignored by JSHint.
    #includepath  "lib"
    #include myBrilantLib.jsx
    /* jshint ignore:end */
    

    or for a single line:

    ignoreThis(); // jshint ignore:line
    

  2. I also tried to figure it out for a long time, until I found the best solution.
    Instead of using:

    #target aftereffects
    

    You can use:

    //@target aftereffects
    

    I didn’t found any documentations for the above solution.

    I just found it in a script over the net, and I tried it and it worked.

    And instead using:

    #include "some/path/to/file.jsx"
    

    As mentioned in the JavaScript Tools Guide:

    evalFile()

    $.evalFile (path[, timeout])

    Loads a JavaScript script file from disk, evaluates it, and returns the result of evaluation.

    path: The name and location of the file.

    timeout: Optional. A number of milliseconds to wait before returning undefined, if the script cannot be evaluated. Default is 10000 milliseconds.

    You can use:

    $.evalFile("some/path/to/file.jsx");
    

    The diffrence is that #include:

    Includes a JavaScript source file from another location.
    Inserts the contents of the named file into this file at the location
    of this statement.

    Login or Signup to reply.
  3. In jshint you can ignore lines by adding a ignore statement to the line.

     #target aftereffects //jshint ignore:line
    

    Or you can ignore whole blocks like this.

    // Code here will be linted with JSHint.
    /* jshint ignore:start */
    // Code here will be ignored by JSHint.
    /* jshint ignore:end */
    

    (BTW the //@target aftereffects is pretty cool. Thanks for pointing that out)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search