0

What's the best way to handle linting when there are multiple files that will be compiled to a single file that share global variables/functions. For example:

file_1.js:

{
const my_flag = 1;
}

file_2.js:

{
  if (my_flag) {
  // etc.

When the two files are compiled and combined, there's no problem. But file_1.js throws a linting error related to an unused variable, and file_2.js throws a linting error related to an undefined variable.

I relize I could ignore the specific lines related to the issue, but that's defeating the purpose of linting the files. What's the best way to share the information between the files during the linting process?

Phil Sinatra
  • 419
  • 3
  • 11
  • why the `{}` brackets ? And also what do you mean by _compiled and combined_ ? Copy paste the content of your two files into a third one ? Maybe you want to consider using modules and a module bundler. – Ulysse BN Aug 14 '17 at 20:29

2 Answers2

1

with eslint you can tell you script that a variable is global:

/* global my_flag */

Put this line before my_flag is used in your second file (generally this is the first line of a file). This will avoid linting error about undefined variable my_flag

Ulysse BN
  • 10,116
  • 7
  • 54
  • 82
0

The .eslintrc configuration file allows naming globals which solved the problem:

"globals": {
  "my_global": true,
  "another_global": true,
  "third_global": true
}

http://eslint.org/docs/user-guide/configuring#specifying-globals

Phil Sinatra
  • 419
  • 3
  • 11