Javascript – Global variables in Javascript and ESLint

eslintglobaljavascriptvariables

I have got multiple javascript files and I have defined some global variable in a file which loads before the others.
As a consequence all of the files loaded after the first have access to the global variable.
However ESLint shows the global variable as "not defined". I don't want to change the rules of ESLint and I would like to find an elegant way to get rid of these error messages.
Any clue?
Thanks

Best Answer

I don't think hacking ESLint rules per file is a great idea.

You should rather define globals in .eslintrc or package.json.

For .eslintrc:

"globals": {
    "angular": true
}

For package.json:

"eslintConfig": {
    "globals": {
        "angular": true
    }
}

Check https://eslint.org/docs/user-guide/configuring/language-options#specifying-globals