Closed Bug 640860 Opened 13 years ago Closed 13 years ago

Validator: Incorrect "Global overwrite"

Categories

(addons.mozilla.org Graveyard :: Admin/Editor Tools, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: nmaier, Assigned: basta)

Details

The "Global overwrite" warning is sometimes incorrect, as it does not take the scope into account.

Correct:
- Actually overriding window/document in a window scope

Incorrect:
- Warning about a function-local variable:
function initWindow(window) {
  let document = window.document;
}
Primary use cases would include js-modules (instead of overlay scripts) as well as bootstrap.js (restartless) add-ons.
Assignee: nobody → mbasta
That functionality is intended. The idea was to prevent the developer from masking global variables and functions in a particular scope. If I'm not mistaken, it was designed to prevent things like this:

var Components = {interfaces: {"nsISomethingorother": /* ... */}};

The JS engine has come a long way, though, and it catches a hell of a lot more problems than it was originally planned to. I'll have to look into the original spec and do some research on what this was specifically intended to protect against, but I'm fairly certain that it can be removed safely.
Fixed:

https://github.com/mattbasta/amo-validator/commit/5a4077f9a69ef89af53e15b7862ab764004cc09a

This will be included in the next pull to mozilla/origin.
Done:

https://github.com/mozilla/amo-validator/pull/6
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Product: addons.mozilla.org → addons.mozilla.org Graveyard
You need to log in before you can comment on or make changes to this bug.