Use global instead of window in JS code
Now that we're using Jest, we are running our plugin code in both Node and Browser environments. This hasn't actually created any issues yet, but I think it'd be nice to rely on Webpack's global variable instead of using window in plugin code and global in our Jest codeβas we currently do.
This is a somewhat aesthetic choice right now, though I think global more clearly expresses our usual intended use of window, and also makes the code a bit more flexible/idiomatic.
This would be a pretty easy search+replace of window in our code that is processed by Webpack.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Use
globaloverwindowin JS code that will be bundled by Webpack.
Implementation Brief
- Add a
no-restricted-globalsrule to oureslintrcencouraging usage ofglobaloverwindow:
"no-restricted-globals": [
"error",
{
"name": "window",
"message": "Use 'global' instead."
}
],
- Convert all existing instances of
windowtoglobal.
Changelog entry
- N/A
@tofumatt Webpack turns this into window when bundling right?
Yup! Everything client-side will continue to work as-normal, but it means our code is a bit more portable for jest, etc. Plus it's just a bit more "standard" use of ES6. π€·ββ
@tofumatt can we enforce this with an ESLint rule? I took a look at the core set but I don't see one for this. Is there maybe a third-party package that you know of that we could leverage?
An easy way might just be to disable usage of window as a global. But I'll have a quick look for anything a bit more codified/pre-made π
IB β
Regression tests on my local and Jurassic Ninja passed.
Tested
-
Setup all services (between Jurassic Ninja and my Local)

-
Deactivated services, disconnected SK. No issues to note.
Passed QA β