4

As I'm setting up ESLint for the first time, I'm a little confused about how it deals with globals.

I've got 40+ js files, (one js file per page in a CRM like application), and some of them are quite long, like 3-4k+ lines. And these JS files share most of their functions in a common file I've named "core.js", which gets included on all pages.

Looking at https://eslint.org/docs/user-guide/configuring#specifying-globals, it looks like it wants me to specify every single function and variable that's used from core.js in my current file, order.js. That just wouldn't be an option, since there's bound to be 50+ global functions/variables that I use, and that list is very subject to change.

Is there not a way to tell ESLint that everything in core.js is global to this file? And on the flip side, it's also telling me that the functions in my core.js aren't ever being used.

Brian Leishman
  • 8,155
  • 11
  • 57
  • 93
  • I think the only(?) alternative is to namespace all the functions in core, and just have that namespace as the global. But that would mean updating how every function in every of your 40+ files is called. – Andy Dec 06 '18 at 20:39
  • @Andy damn that's disappointing... Currently, I use Google's Closure Compiler in advanced mode and it has no problems doing this by allowing me to specify modules like `--module core:1: --js js/core.js --module order:1:core --js js/order.js`, which couldn't more perfect – Brian Leishman Dec 06 '18 at 20:42
  • Another way would be to add `/* global var1, var2 */` to each file. That's a little easier, but still not as direct as the solution you want. – Andy Dec 06 '18 at 20:51
  • @Andy Yes, that's particularly the method I would least like to accomplish this with – Brian Leishman Dec 06 '18 at 20:53
  • @Andy Maybe if I was starting a new project that wouldn't be so rough, but in an existing one that would just take way too much time to set up – Brian Leishman Dec 06 '18 at 20:54

0 Answers0