ESLint-“窗口”没有定义。如何在package.json中允许全局变量 [英] ESLint - "window" is not defined. How to allow global variables in package.json

查看:132
本文介绍了ESLint-“窗口”没有定义。如何在package.json中允许全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为全局窗口对象分配一个属性,但是当我运行eslint时,我得到了:

I am assigning a property to the global window object, but when I run eslint, I get this:


window是未定义

"window" is not defined

我看到此在eslint文档中


以下内容将窗口定义为不应该触发的代码的全局变量要测试的规则:

the following defines window as a global variable for code that should not trigger the rule being tested:



valid: [
  {
    code: "window.alert()",
    globals: [ "window" ]
  }
]

我尝试将此类内容添加到package.json文件中,以使eslint允许将窗口作为全局变量,但是我必须做错了什么。从文档看来,我可能需要在单独的文件中执行类似的操作,但是有没有办法在package.json文件中定义一些允许的全局变量?

I've tried adding something like this to the package.json file to have eslint allow "window" as a global variable, but I must be doing something wrong. From the docs it seems like I might need to do something like this in a separate file, but is there a way to define some allowed global variables right in the package.json file?

推荐答案

我在此页上找到了它: http://eslint.org/ docs / user-guide / configuring

I found it on this page: http://eslint.org/docs/user-guide/configuring

在package.json中,此方法有效:

In package.json, this works:

"eslintConfig": {
  "globals": {
    "window": true
  }
}

这篇关于ESLint-“窗口”没有定义。如何在package.json中允许全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆