JSHint:不包括预处理器指令。不完全是

JSHint: excluding Preprocessor Directives. No, really

我正在使用 Adob​​e Extendscript,它 == javascript*,并且我正在使用 Atom 中的 Atom JSHint 包。 Extendscript 是 Photoshop 和 After Effects 等 Adob​​e 应用程序的脚本框架。 Adobe 确实制作了一个 IDE 但它真的很弱,所以我用 Atom 编写然后切换到 "Extendscript Toolkit" 到 运行 我的脚本。不管怎样……

Adobe 允许您使用 #include "myUsefulFunctions.jsx" 等 C 风格的预处理器指令,这样您就可以像真正的编程语言一样在库中保留可重用的内容。

问题是 JSHint linter 在页面顶部看到了我的 C 风格预处理器指令,惊慌失措并放弃了。为了真正让它对我的代码进行 lint,我必须注释掉预处理器指令,然后记得在我 运行 代码之前取消注释它们。这意味着我每次测试至少要多敲 3 或 4 次按键,这就是众所周知的 了。最坏的。事物。曾经.

因此,为了节省六次击键,我一直在研究 JSHint 的设置。到目前为止,我发现的一切似乎都不相关。有什么方法可以让 JSHint 在全局范围内忽略像 #this 这样的行,或者在文件本地让它跳过一两行?

*还是===?真的被JS的处理方法弄糊涂了

我也想了很久,直到找到最佳方案。 而不是使用:

#target aftereffects

您可以使用:

//@target aftereffects

我没有找到上述解决方案的任何文档。

我刚刚在网上的一个脚本中找到它,我试了一下,它成功了。

而是使用:

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

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.

您可以使用:

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

区别在于#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.

我更改了我使用的 JSHint 包,现在不需要变通方法了。

对于在 Atom 中开发 Extendscript 的任何其他人,我推荐的 linter 是这个:Linter-JSHint. It's a plug-in for the Atom Linter 包,因此您也需要安装它。

然后一旦你完成了使用这个来忽略一个块:

// 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 */

或单行:

ignoreThis(); // jshint ignore:line

在 jshint 中,您可以通过向行添加忽略语句来忽略行。

 #target aftereffects //jshint ignore:line

或者你可以像这样忽略整个块。

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

(顺便说一句,//@target aftereffects 非常酷。感谢您指出这一点)