[英]ESLint not defined / is assigned a value but not used
I'm loading a couple of external JS files and keep getting errors in CodeKit/LSLint (and JSHint) - even though both scripts appear to work as intended when viewing in browser我正在加载几个外部 JS 文件并在 CodeKit/LSLint(和 JSHint)中不断出现错误——即使在浏览器中查看时这两个脚本似乎都按预期工作
All my JS files are loaded below the closing </body>
tag at the foot of the page like so:我所有的 JS 文件都加载到页面底部的结束
</body>
标记下方,如下所示:
<script src="js/vendor/modernizr-3.11.2.min.js"></script>
<script src="js/vendor/rellax.min.js"></script>
<script src="js/vendor/aos.js"></script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
The main.js
file, where I load external scripts currently reads like this:我加载外部脚本的
main.js
文件当前如下所示:
/* RELLAX */
var rellax = new Rellax('.rellax');
/* AOS */
AOS.init();
But returns the following errors:但返回以下错误:
Any ideas how I resolve this?任何想法我如何解决这个问题? I assume the calls in
main.js
are looking for the references in the same place but obviously they're in an external file.我假设
main.js
中的调用正在同一位置查找引用,但显然它们位于外部文件中。 Normally I'd just turn the Hints as everything works but I'd like to resolve if possible...I think previously I've maybe resolved this by wrapping in a function but that didn't work this time (as I'm not using jQUery?)通常我会在一切正常时打开提示,但如果可能的话我想解决......我想以前我可能已经通过包装 function 解决了这个问题,但这次没有用(因为我不使用 jQUery?)
You can specify that those are global variables so that ESLint will not warn about them being undefined.您可以指定这些是全局变量,以便 ESLint 不会警告它们未定义。 The easiest way to do this would be to add the following comment to the top of your
main.js
file.最简单的方法是将以下注释添加到
main.js
文件的顶部。
/* global Rellax:readonly, AOS:readonly */
Or, you could specify the globals in your .eslintrc
file like so:或者,您可以像这样在
.eslintrc
文件中指定全局变量:
{
"globals": {
"Rellax": "readonly",
"AOS": "readonly"
}
}
Check out the ESLint docs for more details.查看ESLint 文档了解更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.