3

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.

stib
  • 3,346
  • 2
  • 30
  • 38
  • 1
    Changing the tool might help: ESHint is newer than JSHint, and also extensible, so you can write your own custom rules (which JSHint, AFAIK, does not allow). – Amadan Dec 07 '15 at 05:03

3 Answers3

3

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.

Community
  • 1
  • 1
Ziki
  • 1,390
  • 1
  • 13
  • 34
  • Nice. Is this documented anywhere? – stib Dec 07 '15 at 05:13
  • 1
    Seems to have a problem with windows relative paths. I tried `$.evalfile("folder\\script.jsx")`, `$.evalfile("folder\script.jsx")` and `$.evalfile("folder/script.jsx")` but it refused to find the file. In the end I went with `'C:\\Program Files\\Adobe\\Adobe After Effects CC 2015\\Support Files\\Scripts\\lib\\myscript.jsx';`. Do you know if there are environmental variables for this path? – stib Dec 07 '15 at 05:36
  • @stib I just edited my answer with more explanation. About the relative path-if you evals a file that it's in the same location as your base script file, you can simply write: `$.evalFile(new File($.fileName).path + '/myscript.jsx')` – Ziki Dec 07 '15 at 05:42
  • I found this question http://stackoverflow.com/a/19635321/432987 which looked like it would be the answer, but it didn't work with any of the Atom JSHint plugins. So it looks like this is the way to go. – stib Dec 07 '15 at 06:03
  • So I made a function called include that I add to the top of my scripts: `function include(includePath){$.evalFile($.fileName.replace(/[^\/]+\.[Jj][Ss][Xx]/, "lib/"+includePath));}` and now I can just use `include("myfile.jsx");` – stib Dec 07 '15 at 06:42
  • 1
    @stib you can avoid the regex by using the above example like: `function include(includePath){$.evalFile(new File($.fileName).path + "/lib/" + includePath));}` but of course use the simple code that fir to you and you understand better. Also you may want to add to your function a validation for existent of the jsx file you want to include. – Ziki Dec 07 '15 at 07:03
  • There's one extra closing bracket in that function, but avoiding the regex is a good idea. – stib Dec 07 '15 at 07:24
1

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)

fabianmoronzirfas
  • 4,091
  • 4
  • 24
  • 41
  • I tried that but it didn't work with the Atom JSHint package I'm using. – stib Dec 07 '15 at 23:16
  • Hm. I remember that I had the same problem once but I can't remember what I did. Turning it off and on again? Uninstall/reinstall/update? My problem was in Sublime Text. – fabianmoronzirfas Dec 08 '15 at 04:29
  • I'll give the case a whack with a spanner. Always works. – stib Dec 08 '15 at 23:35
  • I changed the package I'm using. Now I use https://github.com/AtomLinter/linter-jshint and it works fine. It also doesn't give up if it hits the #include directives. – stib Dec 30 '15 at 03:47
0

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
stib
  • 3,346
  • 2
  • 30
  • 38