no-define-cc-etc.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @fileoverview Reject defining Cc/Ci/Cr/Cu.
  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 componentsBlacklist = ["Cc", "Ci", "Cr", "Cu"];
  10. module.exports = {
  11. meta: {
  12. docs: {
  13. url:
  14. "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/no-define-cc-etc.html",
  15. },
  16. type: "suggestion",
  17. },
  18. create(context) {
  19. return {
  20. VariableDeclarator(node) {
  21. if (
  22. node.id.type == "Identifier" &&
  23. componentsBlacklist.includes(node.id.name)
  24. ) {
  25. context.report(
  26. node,
  27. `${node.id.name} is now defined in global scope, a separate definition is no longer necessary.`
  28. );
  29. }
  30. if (node.id.type == "ObjectPattern") {
  31. for (let property of node.id.properties) {
  32. if (
  33. property.type == "Property" &&
  34. componentsBlacklist.includes(property.value.name)
  35. ) {
  36. context.report(
  37. node,
  38. `${property.value.name} is now defined in global scope, a separate definition is no longer necessary.`
  39. );
  40. }
  41. }
  42. }
  43. },
  44. };
  45. },
  46. };