mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1854948 - Remove support for Cu.import and XPCOMUtils.defineLazyModuleGetter from most of ESLint. r=arai
Differential Revision: https://phabricator.services.mozilla.com/D189132
This commit is contained in:
parent
66ae587f22
commit
c2782050e8
@ -22,7 +22,6 @@ The following patterns are supported:
|
||||
- ``Cu.import("resource://devtools/client/shared/widgets/ViewHelpers.jsm");``
|
||||
- ``loader.lazyRequireGetter(this, "name2"``
|
||||
- ``loader.lazyServiceGetter(this, "name3"``
|
||||
- ``XPCOMUtils.defineLazyModuleGetter(this, "setNamedTimeout", ...)``
|
||||
- ``loader.lazyGetter(this, "toolboxStrings"``
|
||||
- ``XPCOMUtils.defineLazyGetter(this, "clipboardHelper"``
|
||||
- ``ChromeUtils.defineLazyGetter(this, "clipboardHelper"``
|
||||
|
@ -9,14 +9,10 @@ Examples of incorrect code for this rule:
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
Components.utils.import("resource://gre/modules/AppConstants.jsm");
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
obj, "AppConstants", "resource://gre/modules/AppConstants.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(
|
||||
obj, "AppConstants", "resource://gre/modules/AppConstants.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetters(
|
||||
obj, { AppConstants: "resource://gre/modules/AppConstants.jsm" });
|
||||
|
||||
|
@ -15,11 +15,6 @@ Examples of incorrect code for this rule:
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
XPCOMUtils: "resource://gre/modules/XPCOMUtils.jsm",
|
||||
});
|
||||
XPCOMUtils.defineLazyModuleGetter(
|
||||
lazy,
|
||||
"AppConstants",
|
||||
"resource://gre/modules/AppConstants.jsm",
|
||||
});
|
||||
|
||||
Examples of correct code for this rule:
|
||||
---------------------------------------
|
||||
|
@ -19,8 +19,8 @@ Examples of incorrect code for this rule:
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(globalThis, "foo", "foo.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(window, "foo", "foo.jsm");
|
||||
ChromeUtils.defineESModuleGetters(globalThis, { foo: "foo.sys.mjs" });
|
||||
ChromeUtils.defineESModuleGetters(window, { "foo": "foo.sys.mjs" });
|
||||
XPCOMUtils.defineLazyGetter(globalThis, "foo", () => {});
|
||||
XPCOMUtils.defineLazyGetter(window, "foo", () => {});
|
||||
ChromeUtils.defineLazyGetter(globalThis, "foo", () => {});
|
||||
|
@ -10,7 +10,7 @@ Examples of incorrect code for this rule:
|
||||
.. code-block:: js
|
||||
|
||||
const { SomeProp } = ChromeUtils.import("resource://gre/modules/Foo.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(lazy, {
|
||||
ChromeUtils.defineLazyModuleGetters(lazy, {
|
||||
OtherProp: "resource://gre/modules/Foo.jsm",
|
||||
});
|
||||
|
||||
|
@ -18,14 +18,12 @@ const callExpressionDefinitions = [
|
||||
/^loader\.lazyServiceGetter\((?:globalThis|this), "(\w+)"/,
|
||||
/^loader\.lazyRequireGetter\((?:globalThis|this), "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyGetter\((?:globalThis|this), "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyModuleGetter\((?:globalThis|this), "(\w+)"/,
|
||||
/^ChromeUtils\.defineLazyGetter\((?:globalThis|this), "(\w+)"/,
|
||||
/^ChromeUtils\.defineModuleGetter\((?:globalThis|this), "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyPreferenceGetter\((?:globalThis|this), "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyScriptGetter\((?:globalThis|this), "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyServiceGetter\((?:globalThis|this), "(\w+)"/,
|
||||
/^XPCOMUtils\.defineConstant\((?:globalThis|this), "(\w+)"/,
|
||||
/^DevToolsUtils\.defineLazyModuleGetter\((?:globalThis|this), "(\w+)"/,
|
||||
/^DevToolsUtils\.defineLazyGetter\((?:globalThis|this), "(\w+)"/,
|
||||
/^Object\.defineProperty\((?:globalThis|this), "(\w+)"/,
|
||||
/^Reflect\.defineProperty\((?:globalThis|this), "(\w+)"/,
|
||||
|
@ -49,10 +49,7 @@ module.exports = {
|
||||
let { callee } = node;
|
||||
|
||||
if (
|
||||
(isMemberExpression(callee.object, "Components", "utils") ||
|
||||
isIdentifier(callee.object, "Cu") ||
|
||||
isMemberExpression(callee.object, "SpecialPowers", "Cu") ||
|
||||
isIdentifier(callee.object, "ChromeUtils") ||
|
||||
(isIdentifier(callee.object, "ChromeUtils") ||
|
||||
isMemberExpression(
|
||||
callee.object,
|
||||
"SpecialPowers",
|
||||
@ -70,7 +67,6 @@ module.exports = {
|
||||
(isMemberExpression(callee.object, "SpecialPowers", "ChromeUtils") &&
|
||||
isIdentifier(callee.property, "defineModuleGetter")) ||
|
||||
isMemberExpression(callee, "ChromeUtils", "defineModuleGetter") ||
|
||||
isMemberExpression(callee, "XPCOMUtils", "defineLazyModuleGetter") ||
|
||||
isMemberExpression(callee, "XPCOMUtils", "defineLazyModuleGetters")
|
||||
) {
|
||||
context.report({
|
||||
|
@ -59,10 +59,7 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
callerSource === "XPCOMUtils.defineLazyModuleGetter" ||
|
||||
callerSource === "ChromeUtils.defineModuleGetter"
|
||||
) {
|
||||
if (callerSource === "ChromeUtils.defineModuleGetter") {
|
||||
if (node.arguments.length < 3) {
|
||||
return;
|
||||
}
|
||||
|
@ -13,14 +13,12 @@ const callExpressionDefinitions = [
|
||||
/^loader\.lazyServiceGetter\((?:globalThis|window), "(\w+)"/,
|
||||
/^loader\.lazyRequireGetter\((?:globalThis|window), "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyGetter\((?:globalThis|window), "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyModuleGetter\((?:globalThis|window), "(\w+)"/,
|
||||
/^ChromeUtils\.defineLazyGetter\((?:globalThis|window), "(\w+)"/,
|
||||
/^ChromeUtils\.defineModuleGetter\((?:globalThis|window), "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyPreferenceGetter\((?:globalThis|window), "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyScriptGetter\((?:globalThis|window), "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyServiceGetter\((?:globalThis|window), "(\w+)"/,
|
||||
/^XPCOMUtils\.defineConstant\((?:globalThis|window), "(\w+)"/,
|
||||
/^DevToolsUtils\.defineLazyModuleGetter\((?:globalThis|window), "(\w+)"/,
|
||||
/^DevToolsUtils\.defineLazyGetter\((?:globalThis|window), "(\w+)"/,
|
||||
/^Object\.defineProperty\((?:globalThis|window), "(\w+)"/,
|
||||
/^Reflect\.defineProperty\((?:globalThis|window), "(\w+)"/,
|
||||
|
@ -90,10 +90,7 @@ module.exports = {
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
callerSource === "XPCOMUtils.defineLazyModuleGetter" ||
|
||||
callerSource === "ChromeUtils.defineModuleGetter"
|
||||
) {
|
||||
if (callerSource === "ChromeUtils.defineModuleGetter") {
|
||||
if (node.arguments.length < 3) {
|
||||
return;
|
||||
}
|
||||
|
@ -26,14 +26,12 @@ const callExpressionDefinitions = [
|
||||
/^loader\.lazyRequireGetter\(lazy, "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyGetter\(lazy, "(\w+)"/,
|
||||
/^Integration\.downloads\.defineESModuleGetter\(lazy, "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyModuleGetter\(lazy, "(\w+)"/,
|
||||
/^ChromeUtils\.defineLazyGetter\(lazy, "(\w+)"/,
|
||||
/^ChromeUtils\.defineModuleGetter\(lazy, "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyPreferenceGetter\(lazy, "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyScriptGetter\(lazy, "(\w+)"/,
|
||||
/^XPCOMUtils\.defineLazyServiceGetter\(lazy, "(\w+)"/,
|
||||
/^XPCOMUtils\.defineConstant\(lazy, "(\w+)"/,
|
||||
/^DevToolsUtils\.defineLazyModuleGetter\(lazy, "(\w+)"/,
|
||||
/^DevToolsUtils\.defineLazyGetter\(lazy, "(\w+)"/,
|
||||
/^Object\.defineProperty\(lazy, "(\w+)"/,
|
||||
/^Reflect\.defineProperty\(lazy, "(\w+)"/,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "eslint-plugin-mozilla",
|
||||
"version": "3.2.0",
|
||||
"version": "3.3.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "eslint-plugin-mozilla",
|
||||
"version": "3.2.0",
|
||||
"version": "3.3.0",
|
||||
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
|
||||
"keywords": [
|
||||
"eslint",
|
||||
|
@ -36,22 +36,10 @@ ruleTester.run("reject-chromeutils-import", rule, {
|
||||
'ChromeUtils.defineESModuleGetters(obj, { My: "resource://some/path/to/My.sys.mjs" })',
|
||||
],
|
||||
invalid: [
|
||||
{
|
||||
code: 'Components.utils.import("resource://some/path/to/My.jsm")',
|
||||
errors: invalidError,
|
||||
},
|
||||
{
|
||||
code: 'Cu.import("resource://some/path/to/My.jsm")',
|
||||
errors: invalidError,
|
||||
},
|
||||
{
|
||||
code: 'ChromeUtils.import("resource://some/path/to/My.jsm")',
|
||||
errors: invalidError,
|
||||
},
|
||||
{
|
||||
code: 'SpecialPowers.Cu.import("resource://some/path/to/My.jsm")',
|
||||
errors: invalidError,
|
||||
},
|
||||
{
|
||||
code: 'SpecialPowers.ChromeUtils.import("resource://some/path/to/My.jsm")',
|
||||
errors: invalidError,
|
||||
@ -64,10 +52,6 @@ ruleTester.run("reject-chromeutils-import", rule, {
|
||||
code: 'SpecialPowers.ChromeUtils.defineModuleGetter(obj, "My", "resource://some/path/to/My.jsm")',
|
||||
errors: invalidErrorLazy,
|
||||
},
|
||||
{
|
||||
code: 'XPCOMUtils.defineLazyModuleGetter(obj, "My", "resource://some/path/to/My.jsm")',
|
||||
errors: invalidErrorLazy,
|
||||
},
|
||||
{
|
||||
code: 'XPCOMUtils.defineLazyModuleGetters(obj, { My: "resource://some/path/to/My.jsm" })',
|
||||
errors: invalidErrorLazy,
|
||||
|
@ -22,11 +22,6 @@ function invalidCode(code, uri) {
|
||||
|
||||
ruleTester.run("reject-eager-module-in-lazy-getter", rule, {
|
||||
valid: [
|
||||
`
|
||||
XPCOMUtils.defineLazyModuleGetter(
|
||||
lazy, "Integration", "resource://gre/modules/Integration.jsm"
|
||||
);
|
||||
`,
|
||||
`
|
||||
ChromeUtils.defineModuleGetter(
|
||||
lazy, "Integration", "resource://gre/modules/Integration.jsm"
|
||||
@ -44,14 +39,6 @@ ruleTester.run("reject-eager-module-in-lazy-getter", rule, {
|
||||
`,
|
||||
],
|
||||
invalid: [
|
||||
invalidCode(
|
||||
`
|
||||
XPCOMUtils.defineLazyModuleGetter(
|
||||
lazy, "AppConstants", "resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
`,
|
||||
"resource://gre/modules/AppConstants.jsm"
|
||||
),
|
||||
invalidCode(
|
||||
`
|
||||
ChromeUtils.defineModuleGetter(
|
||||
|
@ -70,11 +70,6 @@ ruleTester.run("reject-globalThis-modification", rule, {
|
||||
ChromeUtils.defineESMGetters(globalThis, {
|
||||
AppConstants: "resource://gre/modules/AppConstants.sys.mjs",
|
||||
});
|
||||
`),
|
||||
invalidCall(`
|
||||
XPCOMUtils.defineLazyModuleGetter(
|
||||
globalThis, "AppConstants", "resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
`),
|
||||
invalidCall(`
|
||||
XPCOMUtils.defineLazyModuleGetters(globalThis, {
|
||||
|
@ -38,10 +38,6 @@ ruleTester.run("reject-lazy-imports-into-globals", rule, {
|
||||
invalidCode(`XPCOMUtils.defineLazyGetter(window, "foo", () => {});`),
|
||||
invalidCode(`ChromeUtils.defineLazyGetter(globalThis, "foo", () => {});`),
|
||||
invalidCode(`ChromeUtils.defineLazyGetter(window, "foo", () => {});`),
|
||||
invalidCode(
|
||||
`XPCOMUtils.defineLazyModuleGetter(globalThis, "foo", "foo.jsm");`
|
||||
),
|
||||
invalidCode(`XPCOMUtils.defineLazyModuleGetter(window, "foo", "foo.jsm");`),
|
||||
invalidCode(
|
||||
`XPCOMUtils.defineLazyPreferenceGetter(globalThis, "foo", "foo.bar");`
|
||||
),
|
||||
|
@ -32,11 +32,6 @@ ruleTester.run("reject-mixing-eager-and-lazy", rule, {
|
||||
`,
|
||||
`
|
||||
import{ AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
|
||||
`,
|
||||
`
|
||||
XPCOMUtils.defineLazyModuleGetter(
|
||||
lazy, "AppConstants", "resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
`,
|
||||
`
|
||||
ChromeUtils.defineModuleGetter(
|
||||
@ -57,15 +52,9 @@ ruleTester.run("reject-mixing-eager-and-lazy", rule, {
|
||||
if (some_condition) {
|
||||
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
||||
}
|
||||
XPCOMUtils.defineLazyModuleGetter(
|
||||
lazy, "AppConstants", "resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
`,
|
||||
`
|
||||
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(
|
||||
sandbox, "AppConstants", "resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
AppConstants: "resource://gre/modules/AppConstants.jsm"
|
||||
});
|
||||
`,
|
||||
`
|
||||
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
||||
@ -75,15 +64,6 @@ ruleTester.run("reject-mixing-eager-and-lazy", rule, {
|
||||
`,
|
||||
],
|
||||
invalid: [
|
||||
invalidCode(
|
||||
`
|
||||
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(
|
||||
lazy, "AppConstants", "resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
`,
|
||||
"resource://gre/modules/AppConstants.jsm"
|
||||
),
|
||||
invalidCode(
|
||||
`
|
||||
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
||||
|
@ -34,13 +34,6 @@ ruleTester.run("valid-lazy", rule, {
|
||||
ChromeUtils.defineLazyGetter(lazy, "foo", () => {});
|
||||
if (x) { lazy.foo.bar(); }
|
||||
`,
|
||||
`
|
||||
const lazy = {};
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
foo: "foo.jsm",
|
||||
});
|
||||
if (x) { lazy.foo.bar(); }
|
||||
`,
|
||||
`
|
||||
const lazy = {};
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
|
Loading…
Reference in New Issue
Block a user