Closed Bug 1328565 Opened 9 years ago Closed 9 years ago

[eslint] Figure out how/if to handle importing globals from "var foo = Cu.import("...", this);"

Categories

(Developer Infrastructure :: Lint and Formatting, defect)

3 Branch
defect
Not set
normal

Tracking

(firefox53 fixed)

RESOLVED FIXED
mozilla53
Tracking Status
firefox53 --- fixed

People

(Reporter: standard8, Assigned: standard8)

References

Details

Attachments

(2 files)

Currently, when the import-globals plugin runs, it doesn't detect globals imported via: ``` var foo = Cu.import("bar.jsm", this); ``` The expected result is that `foo` and `bar` should both be globals here. However, currently only `foo` is a global. The plugin doesn't detect this case, as it expects the `Cu.import` to be at the beginning of the line. I'd also argue that this is a non-obvious case: we're importing into a specific variable *and* the global scope. To me, that feel unexpected, and I think we should consider banning this case.
As far as I can tell, there's only four instances of this in the tree: https://dxr.mozilla.org/mozilla-central/search?q=regexp%3A%5Evar.*%3D.*Components.utils.import%5C(%5B%27%22%5D.*%5C.js.*%2C+this)%3B&redirect=false -> toolkit/modules/tests/browser/browser_Battery.js https://dxr.mozilla.org/mozilla-central/search?q=regexp%3A%5Evar.*%3D.*Cu.import%5C(%5B%27%22%5D.*%5C.js.*%2C+this)%3B&redirect=false -> toolkit/components/crashes/tests/xpcshell/test_crash_manager.js -> toolkit/components/crashes/tests/xpcshell/test_crash_service.js -> toolkit/components/crashes/tests/xpcshell/test_crash_store.js
Due to the low occurrences, awkwardness of the behavior, as well as where this practice is used (tests only) I'm fine with removing these and banning them.
Assignee: nobody → standard8
Comment on attachment 8823781 [details] Bug 1328565 - Prevent cases of Cu.import importing into variables and global scope at the same time. https://reviewboard.mozilla.org/r/102300/#review102686
Attachment #8823781 - Flags: review?(dtownsend) → review+
Pushed by mbanner@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/b6d798426ca0 Prevent cases of Cu.import importing into variables and global scope at the same time. r=mossop
I just realised that I forgot to bump the eslint-plugin-mozilla version, hence developers won't automatically pick up the new files. Going to get this landed as a bustage fix for developers.
Attachment #8823981 - Flags: review+
Pushed by cbook@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/01d4695721e1 bump the eslint-plugin-mozilla version to ensure developers get the changes installed properly. r=bustage-fix
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla53
Blocks: 1329614
Product: Testing → Firefox Build System
Version: Version 3 → 3 Branch
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: