reject-relative-requires.js 910 B

123456789101112131415161718192021222324252627282930313233343536
  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. const isRelativePath = function(path) {
  11. return path.startsWith("./") || path.startsWith("../");
  12. };
  13. module.exports = {
  14. meta: {
  15. docs: {
  16. url:
  17. "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/reject-relative-requires.html",
  18. },
  19. type: "problem",
  20. },
  21. create(context) {
  22. return {
  23. CallExpression(node) {
  24. const path = helpers.getDevToolsRequirePath(node);
  25. if (path && isRelativePath(path)) {
  26. context.report(node, "relative paths are not allowed with require()");
  27. }
  28. },
  29. };
  30. },
  31. };