valid-lazy¶
确保 lazy
对象上属性的定义和使用有效。此规则检查是否使用了未知属性、重复的符号、未使用的符号,以及在顶层无条件使用延迟获取器。
此规则不正确的代码示例:¶
const lazy = {};
if (x) {
// Unknown lazy member property {{name}}
lazy.bar.foo();
}
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();
}
const lazy = {};
// Unused lazy property foo
ChromeUtils.defineESModuleGetters(lazy, { foo: "foo.sys.mjs"});
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, { foo: "foo.sys.mjs"});
// Used at top-level unconditionally.
lazy.foo.bar();
此规则正确的代码示例:¶
const lazy = {};
ChromeUtils.defineLazyGetter(lazy, "foo1", () => {});
ChromeUtils.defineESModuleGetters(lazy, { foo2: "foo2.sys.mjs"});
if (x) {
lazy.foo1.bar();
lazy.foo2.bar();
}