What is the purpose of SharedArrayBuffer
, and Atomics
, being added to the .eslintrc.json
configuration file's "globals"
property?
/** @file "./.eslintrc.json" */
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
}
I suppose that the appropriate place to start would by telling the readers that JavaScript implements Built-In Global Variables. What that means is: Before JavaScript runs, the JS-Engine initializes predefined variables as defined by the ECMAScript standard, which are implemented by those who write the JavaScript Engines (V8, Spider-Monkey, ect...). Built in globals are extremely assessable, in-fact they are accessible everywhere in JavaScript.
The variables don't even have to be declared, or initiated. To put even more simply, from the perspective of a JavaScript program, they always exist, and they are always accessible, and it is exactly these traits that make built-in globals an issue for development tools, in-particularly "ESLint".
"ESLint" knows when a variable has been defined, because it parses through your code — once it arrives at a variable's declaration, it records the declaration. ESLint uses the data it collects about variable declarations to know a few different "things" about variables, but what we care about, is that it uses the data to know if a variable being used, was previously declared, if it was not declared, ESLint displays an Error
. Because, as stated previously, the globals are never declared, ESLint displays an error, even though the code is valid, and if you did what ESLint suggested, and declared the global, that would not just be an error, it would be stupid (pardon my French, but I think most would agree), so in order to avoid all this chaos, ESLint offers the ability to declare any Globals, pre-built or not, in a special "globals":{}
of that variable. By working in the way I just described, ESLint is able to notify you when a variable, that has been declared, is not being used by the program
by parsing your script, and ready the part where you defined any arbitrary variable, and since you don't define built-in globals, ESLint can't tell that they have been instantiated, unless of-course, you declare them as a global in your eslintrc.json
(or if your a rebel, .eslintrc.yaml
) "globals":{}
property, that can be found in the .eslintrc.json
(or for rebels, the .eslintrc.yaml
file).
So, at the end of the day, you can see that Atomics & SharedArrayBuffer are builtin globals, that ESLint does not recognize. Since you are asking about them, I assume you are not useing them, and if my assumption is correct, them you should remove them. Don't declare any globals that your not using ever. I don't know how Atomics & SharedArrayBuffer first started being defaulty included as globals in ESLint configuration files, but as far as I can tell, the practice is unjustified, and I only see it in "run-of-the-mill" tutorials shown around the internet. If anything, it should be Mocha globals that are included, as it is far more common for JavaScript developers to test with Mocha, than work with Atomics & SharedArrayBuffer, but Mocha isn't built-in so that actually might be silly. IMO, if your not using the global, don't declare it anywhere, not even in configuration files.
If you want to know what all the
built-in globals
are, you can follow the link above — its included at the start of this answer.