summaryrefslogtreecommitdiffstats
path: root/docs/code-quality/lint/linters/eslint-plugin-mozilla/rules/valid-lazy.rst
blob: e7f6706d5b07d756647d0a0914825827c0e0c59a (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
49
50
51
52
53
54
55
valid-lazy
==========

Ensures that definitions and uses of properties on the ``lazy`` object are valid.
This rule checks for using unknown properties, duplicated symbols, unused
symbols, and also lazy getter used at top-level unconditionally.

Examples of incorrect code for this rule:
-----------------------------------------

.. code-block:: js

    const lazy = {};
    if (x) {
      // Unknown lazy member property {{name}}
      lazy.bar.foo();
    }

.. code-block:: js

    const lazy = {};
    ChromeUtils.defineESModuleGetters(lazy, { foo: "foo.sys.mjs"});

    // Duplicate symbol foo being added to lazy.
    ChromeUtils.defineLazyGetter(lazy, "foo", () => {});
    if (x) {
      lazy.foo3.bar();
    }

.. code-block:: js

    const lazy = {};
    // Unused lazy property foo
    ChromeUtils.defineESModuleGetters(lazy, { foo: "foo.sys.mjs"});

.. code-block:: js

    const lazy = {};
    ChromeUtils.defineESModuleGetters(lazy, { foo: "foo.sys.mjs"});
    // Used at top-level unconditionally.
    lazy.foo.bar();

Examples of correct code for this rule:
---------------------------------------

.. code-block:: js

    const lazy = {};
    ChromeUtils.defineLazyGetter(lazy, "foo1", () => {});
    ChromeUtils.defineESModuleGetters(lazy, { foo2: "foo2.sys.mjs"});

    if (x) {
      lazy.foo1.bar();
      lazy.foo2.bar();
    }