Loading devtools/client/shared/test-helpers/jest-fixtures/Services.js +2 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ // This fixture is probably doing too much and should be reduced to the minimum // needed to pass the tests. /* eslint-disable mozilla/valid-services */ // Some constants from nsIPrefBranch.idl. const PREF_INVALID = 0; const PREF_STRING = 32; Loading docs/code-quality/lint/linters/eslint-plugin-mozilla/valid-services.rst 0 → 100644 +22 −0 Original line number Diff line number Diff line valid-services ============== Ensures that accesses of the ``Services`` object are valid. Examples of incorrect code for this rule: ----------------------------------------- Assuming ``foo`` is not defined within Services. .. code-block:: js Services.foo.fn(); Examples of correct code for this rule: --------------------------------------- Assuming ``bar`` is defined within Services. .. code-block:: js Services.bar.fn(); tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js +1 −0 Original line number Diff line number Diff line Loading @@ -179,6 +179,7 @@ module.exports = { "mozilla/use-ownerGlobal": "error", "mozilla/use-returnValue": "error", "mozilla/use-services": "error", "mozilla/valid-services": "error", // Use [] instead of Array() "no-array-constructor": "error", Loading tools/lint/eslint/eslint-plugin-mozilla/lib/index.js +1 −0 Original line number Diff line number Diff line Loading @@ -73,6 +73,7 @@ module.exports = { "use-isInstance": require("./rules/use-isInstance"), "use-returnValue": require("../lib/rules/use-returnValue"), "use-services": require("../lib/rules/use-services"), "valid-services": require("../lib/rules/valid-services"), "var-only-at-top-level": require("../lib/rules/var-only-at-top-level"), }, }; tools/lint/eslint/eslint-plugin-mozilla/lib/rules/valid-services.js 0 → 100644 +59 −0 Original line number Diff line number Diff line /** * @fileoverview Require use of Services.* rather than getService. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; const helpers = require("../helpers"); module.exports = { meta: { docs: { url: "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/use-services.html", }, type: "problem", }, create(context) { let servicesInterfaceMap = helpers.servicesData; let serviceAliases = new Set([ ...Object.values(servicesInterfaceMap), // This is defined only for Android, so most builds won't pick it up. "androidBridge", // These are defined without interfaces and hence are not in the services map. "cpmm", "crashmanager", "mm", "ppmm", // The new xulStore also does not have an interface. "xulStore", ]); return { MemberExpression(node) { if (node.computed || node.object.type !== "Identifier") { return; } let alias; if (node.object.name == "Services") { alias = node.property.name; } else if ( node.property.name == "Services" && node.parent.type == "MemberExpression" ) { alias = node.parent.property.name; } else { return; } if (!serviceAliases.has(alias)) { context.report(node, `Unknown Services member property ${alias}`); } }, }; }, }; Loading
devtools/client/shared/test-helpers/jest-fixtures/Services.js +2 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ // This fixture is probably doing too much and should be reduced to the minimum // needed to pass the tests. /* eslint-disable mozilla/valid-services */ // Some constants from nsIPrefBranch.idl. const PREF_INVALID = 0; const PREF_STRING = 32; Loading
docs/code-quality/lint/linters/eslint-plugin-mozilla/valid-services.rst 0 → 100644 +22 −0 Original line number Diff line number Diff line valid-services ============== Ensures that accesses of the ``Services`` object are valid. Examples of incorrect code for this rule: ----------------------------------------- Assuming ``foo`` is not defined within Services. .. code-block:: js Services.foo.fn(); Examples of correct code for this rule: --------------------------------------- Assuming ``bar`` is defined within Services. .. code-block:: js Services.bar.fn();
tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js +1 −0 Original line number Diff line number Diff line Loading @@ -179,6 +179,7 @@ module.exports = { "mozilla/use-ownerGlobal": "error", "mozilla/use-returnValue": "error", "mozilla/use-services": "error", "mozilla/valid-services": "error", // Use [] instead of Array() "no-array-constructor": "error", Loading
tools/lint/eslint/eslint-plugin-mozilla/lib/index.js +1 −0 Original line number Diff line number Diff line Loading @@ -73,6 +73,7 @@ module.exports = { "use-isInstance": require("./rules/use-isInstance"), "use-returnValue": require("../lib/rules/use-returnValue"), "use-services": require("../lib/rules/use-services"), "valid-services": require("../lib/rules/valid-services"), "var-only-at-top-level": require("../lib/rules/var-only-at-top-level"), }, };
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/valid-services.js 0 → 100644 +59 −0 Original line number Diff line number Diff line /** * @fileoverview Require use of Services.* rather than getService. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; const helpers = require("../helpers"); module.exports = { meta: { docs: { url: "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/use-services.html", }, type: "problem", }, create(context) { let servicesInterfaceMap = helpers.servicesData; let serviceAliases = new Set([ ...Object.values(servicesInterfaceMap), // This is defined only for Android, so most builds won't pick it up. "androidBridge", // These are defined without interfaces and hence are not in the services map. "cpmm", "crashmanager", "mm", "ppmm", // The new xulStore also does not have an interface. "xulStore", ]); return { MemberExpression(node) { if (node.computed || node.object.type !== "Identifier") { return; } let alias; if (node.object.name == "Services") { alias = node.property.name; } else if ( node.property.name == "Services" && node.parent.type == "MemberExpression" ) { alias = node.parent.property.name; } else { return; } if (!serviceAliases.has(alias)) { context.report(node, `Unknown Services member property ${alias}`); } }, }; }, };