如何让JSLint忽略代码片段?

时间:2014-06-14 20:04:58

标签: javascript jslint

我的php文件主要有几个我想调试的javascript函数。该文件以:

开头
/*ignore jslint start*/
<? Header("content-type: application/x-javascript");
include('../country files/' . $_GET['country'] . '.php');
?>
/*ignore jslint end*/
  ...
  javascript code

虽然,JSLint在第1行给出错误!

1 个答案:

答案 0 :(得分:3)

您可以使用注释更改几行的JSLint选项。

例如,JSLint会抱怨您使用Underscore.JSLo-Dash,因为在变量名称的末尾加上下划线并不是一个好习惯。但我可以通过暂时阻止nomen警告来愉快地使用Underscore的each()功能:

/*jslint nomen:true*/ // suppress dangling underscore warnings
_.each( ... ); // example use of Underscore.JS
/*jslint nomen:false*/ // re-enable dangling underscore warnings

但是,没有办法使用注释来完全暂时禁用JSLint。

将JavaScript移到单独的文件中是一种很好的做法。理想情况下,您不应该在HTML或PHP文件上运行JSLint,只能在纯JavaScript文件上运行。

如果您需要使用PHP动态生成JavaScript代码,那么就可以在输出样本上运行JSlint。通常,您最小化必要的情况。

您可以让PHP生成少量JavaScript来建立操作上下文(例如一些全局常量),并将剩下的前端功能留给单独的纯JavaScript文件。

相关问题