简体   繁体   English

ESLint 未定义/被赋值但未使用

[英]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:但返回以下错误:

CodeKit / JSLint 错误信息

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.

相关问题 'confirmPassword' 被分配了一个值但从未使用过.eslint - 'confirmPassword' is assigned a value but never used.eslint ESLint - 出现错误 - &#39;expect&#39; 被分配了一个值但从未使用过 - ESLint - Getting error - 'expect' is assigned a value but never used Eslint throws 被分配了一个值但从未使用过,webpack 模块 - Eslint throws is assigned a value but never used , webpack module 为[eslint]&#39;值&#39;分配了一个值,但在对vue.js全栈应用程序使用joi验证时从未使用过 - Getting [eslint] 'value' is assigned a value but never used when using joi validation for vue.js fullstack application Eslint - 在定义之前使用了“观察者”? - Eslint - 'observer' was used before it was defined? “&#39;React&#39; 在定义之前就被使用了。” eslint 警告 - “'React' was used before it was defined.” eslint warning 如何修复 eslint 在反应中的“组件已定义但从未使用”? - How to fix "Component is defined but never used" for eslint in react? React中的无状态组件和“Props已定义但从未使用过”ESLint错误 - Stateless component in React and “Props is defined but never used” ESLint error 仅在一个文件中使用 ESLint “require is not defined”时如何解决? - How to fix ESLint “require is not defined” when it is used in just one file? eslint:禁用警告-特定 function 的“已定义但从未使用”? - eslint: disable warning - `defined but never used` for specific function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM