valid-services.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @fileoverview Ensures that Services uses have valid property names.
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. "use strict";
  9. const helpers = require("../helpers");
  10. module.exports = {
  11. meta: {
  12. docs: {
  13. url:
  14. "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/valid-services.html",
  15. },
  16. type: "problem",
  17. },
  18. create(context) {
  19. let servicesInterfaceMap = helpers.servicesData;
  20. let serviceAliases = new Set([
  21. ...Object.values(servicesInterfaceMap),
  22. // This is defined only for Android, so most builds won't pick it up.
  23. "androidBridge",
  24. // These are defined without interfaces and hence are not in the services map.
  25. "cpmm",
  26. "crashmanager",
  27. "mm",
  28. "ppmm",
  29. // The new xulStore also does not have an interface.
  30. "xulStore",
  31. ]);
  32. return {
  33. MemberExpression(node) {
  34. if (node.computed || node.object.type !== "Identifier") {
  35. return;
  36. }
  37. let alias;
  38. if (node.object.name == "Services") {
  39. alias = node.property.name;
  40. } else if (
  41. node.property.name == "Services" &&
  42. node.parent.type == "MemberExpression"
  43. ) {
  44. alias = node.parent.property.name;
  45. } else {
  46. return;
  47. }
  48. if (!serviceAliases.has(alias)) {
  49. context.report(node, `Unknown Services member property ${alias}`);
  50. }
  51. },
  52. };
  53. },
  54. };