reject-some-requires.js 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @fileoverview Reject some uses of require.
  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. var 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/reject-some-requires.html",
  15. },
  16. schema: [
  17. {
  18. type: "string",
  19. },
  20. ],
  21. type: "problem",
  22. },
  23. create(context) {
  24. if (typeof context.options[0] !== "string") {
  25. throw new Error("reject-some-requires expects a regexp");
  26. }
  27. const RX = new RegExp(context.options[0]);
  28. return {
  29. CallExpression(node) {
  30. const path = helpers.getDevToolsRequirePath(node);
  31. if (path && RX.test(path)) {
  32. context.report(node, `require(${path}) is not allowed`);
  33. }
  34. },
  35. };
  36. },
  37. };