Javascript和ESLint中的全局变量 [英] Global variables in Javascript and ESLint
问题描述
我有多个javascript文件,我在一个文件中定义了一些全局变量,该文件在其他文件之前加载。
因此,在第一个文件之后加载的所有文件都可以访问全局变量。
但是,ESLint将全局变量显示为未定义。我不想改变ESLint的规则,我想找到一种优雅的方法来摆脱这些错误信息。
任何线索?
谢谢
I have got multiple javascript files and I have defined some global variable in a file which loads before the others. As a consequence all of the files loaded after the first have access to the global variable. However ESLint shows the global variable as "not defined". I don't want to change the rules of ESLint and I would like to find an elegant way to get rid of these error messages. Any clue? Thanks
推荐答案
我不认为每个文件的黑客ESLint规则是个好主意。
I don't think hacking ESLint rules per file is a great idea.
您应该在 .eslintrc
或 globals
>的package.json 。
You should rather define globals
in .eslintrc
or package.json
.
对于.eslintrc:
For .eslintrc:
"globals": {
"angular": true
}
对于包。 json
:
"eslintConfig": {
"globals": {
"angular": true
}
}
PS
阅读文档是开发人员的必备条件
Reading documentation is a virtue mandatory for developers
https://eslint.org/docs/user-guide/configuring#specifying-globals
这篇关于Javascript和ESLint中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!