简体   繁体   English

esLint 全局变量 - 用正则表达式还是通配符定义?

[英]esLint globals - define with regex or wildcard?

I am trying to use esLint in a Javascript file that is used as a source for SharePoint content editor webpart and I use an external JS library which is loaded elsewhere by the external solution itself.我正在尝试在用作 SharePoint 内容编辑器 webpart 源的 Javascript 文件中使用 esLint,并且我使用外部解决方案本身在其他地方加载的外部 JS 库。 Therefore I don't need to import them in my files myself.因此我不需要自己将它们导入到我的文件中。

In my .eslintrc.js I want to specify the functions defined in the external library by a wildcard or regex, eg like this在我的 .eslintrc.js 中,我想通过通配符或正则表达式指定外部库中定义的函数,例如像这样

'globals': { myLib_*: true }

or或者

'globals': { /myLib_[^\\s]+/: true }

so calls of any function starting with myLib_ are not marked as no-undef所以任何以 myLib_ 开头的函数的调用都不会被标记为no-undef

Is this possible or not?这可能吗? If it is not, I can put the external library on my filesystem and then reference it in the .eslintrc.js how?如果不是,我可以将外部库放在我的文件系统上,然后如何在 .eslintrc.js 中引用它?

Thank you!谢谢!

Based on these closed issues, it unfortunately looks like it won't be supported 😞基于这些已关闭的问题,不幸的是它似乎不会得到支持 😞

ESLint contributer nzakas stated in a comment in 2015 that ESLint 贡献者 nzakas 在 2015 年的评论中表示

Globals can't work with unknown values because we do full scope resolution, not just identifier name matching.全局变量无法处理未知值,因为我们进行全范围解析,而不仅仅是标识符名称匹配。

  • github.com/eslint/eslint/issues/4158 github.com/eslint/eslint/issues/4158
  • github.com/eslint/eslint/issues/12138 github.com/eslint/eslint/issues/12138

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM