Closed Bug 1509270 Opened Last year Closed Last year

[eslint] Consider allowing writing to 'location' variable


(Firefox Build System :: Lint and Formatting, enhancement)

Not set


(firefox65 fixed)

Tracking Status
firefox65 --- fixed


(Reporter: standard8, Assigned: standard8)



(1 file)

Boris pointed out off-line that ESLint doesn't allow writing to the `location` variable - it fails for the "no-global-assign" rule.

The documentation says that although location is read-only, you can assign a DOMString to it.

The definition built into ESLint via the browser environment, marks it as read-only:

That seems to date back to when it was first added, so the write nature may have not been considered, or it was considered and decided not to allow due to the restricted item you can assign to it.

The workaround is to use the slightly longer window.location.

I'm thinking we could possibly allow writing to location for browser/chrome/mochitest tests. However, at the moment I'm only seeing about 18 instances throughout the tree, but maybe that's because people have been using the longer version:*location+%3D&case=false&regexp=true&path=*.html
> The documentation says that although location is read-only, you can assign a DOMString to it. 

It's "readonly" but [PutForwards], so there is actually a setter, and that setter forwards the set to the location object's href attribute.  See

Also, there are no restrictions on what you can assign.  Whatever JS value you assign will have applied to it before being passed on into the browser.  So you can assign objects, whatever. ;)

Basically, "location" is not actually readonly.  It's a writable property in Window.
Thanks for the clarification.
Assignee: nobody → standard8
I've raised a PR to change the original source of the global definition for ESLint:

In the meantime, as this might affect some tests that I have people working on, I'm proposing the attached patch as a temporary fix.
No movement on the PR yet, so I'll land the fix as is, and keep an eye out later on.
Pushed by
Allow 'location' as a writeable global property for ESLint (previously read-only). r=mossop
Closed: Last year
Resolution: --- → FIXED
Target Milestone: --- → Firefox 65
Target Milestone: Firefox 65 → mozilla65
You need to log in before you can comment on or make changes to this bug.