0

I have put a pre-commit script in my git hooks so that it uses eslint before committing the nodejs code. It analyses only the files that are to be committed. I had declare a global variable in my main entry point to my project. This is how I did it.

global.foo = true

The problem that I am facing now is, I am using this foo variable at many places in my code and without using global extension (which is valid in nodejs)

if(foo)
    // do somethins
else
    // do nothing

the code works perfectly as this is valid use of global variable. But when I commit the code, the eslint shows error on all the uses of foo saying that it is undeclared.

error  "foo" is not defined  no-undef

I cant think of any solution for this. Please suggest a workaround

molecule
  • 1,027
  • 1
  • 14
  • 27

2 Answers2

1

The official docs describe how you can tell eslint about globals:

/*global foo b:true*/

should do.

This answer adds and additional way to do it

Subhi Dweik
  • 101
  • 4
1

In your eslintrc file add rule:

{
    globals: {
        'foo': true
    }
}
kaxi1993
  • 4,535
  • 4
  • 29
  • 47