Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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, e.g. like this

'globals': {
  myLib_*: true
}

or

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

so calls of any function starting with myLib_ are not marked as 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?

Thank you!

like image 256
Martin Bondy Petvalsky Avatar asked Sep 11 '25 10:09

Martin Bondy Petvalsky


1 Answers

Based on the closed issues below, it unfortunately looks like it won't be supported 😞

ESLint contributer nzakas stated in a comment in 2015 that

Globals can't work with unknown values because we do full scope resolution, not just identifier name matching.

  • eslint/eslint#4158 — Regex support for globals
  • eslint/eslint#12138 — Support regex for globals in config
like image 107
Fullchee Zhang Avatar answered Sep 14 '25 00:09

Fullchee Zhang