summaryrefslogtreecommitdiffstats
path: root/docs/code-quality/lint/linters/eslint-plugin-mozilla/rules/reject-importGlobalProperties.rst
blob: 60e2a3887be2fd601490f1246f1762c6939d07a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
reject-importGlobalProperties
=============================

Rejects calls to ``Cu.importGlobalProperties`` or
``XPCOMUtils.defineLazyGlobalGetters``.

In system modules all the required properties should already be available. In
non-module code or non-system modules, webidl defined interfaces should already
be available and hence do not need importing.

For sjs test files, if the relevant global is not already available, then consider
extending the `list of globals available from the httpd server <https://searchfox.org/mozilla-central/rev/e9b338c2d597067f99e96d5f20769f41f312fa8f/netwerk/test/httpserver/httpd.sys.mjs#2875-2889>`_.

Options
-------

* "everything": Disallows using the import/getters completely.
* "allownonwebidl": Disallows using the import functions for webidl symbols. Allows
  other symbols.

everything
----------

Incorrect code for this option:

.. code-block:: js

    Cu.importGlobalProperties(['TextEncoder']);
    XPCOMUtils.defineLazyGlobalGetters(this, ['TextEncoder']);

allownonwebidl
--------------

Incorrect code for this option:

.. code-block:: js

    // AnimationEffect is a webidl property.
    Cu.importGlobalProperties(['AnimationEffect']);
    XPCOMUtils.defineLazyGlobalGetters(this, ['AnimationEffect']);

Correct code for this option:

.. code-block:: js

    // TextEncoder is not defined by webidl.
    Cu.importGlobalProperties(['TextEncoder']);
    XPCOMUtils.defineLazyGlobalGetters(this, ['TextEncoder']);