no-extraneous-require.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @author Toru Nagashima
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. const checkExtraneous = require("../util/check-extraneous")
  7. const getAllowModules = require("../util/get-allow-modules")
  8. const getConvertPath = require("../util/get-convert-path")
  9. const getResolvePaths = require("../util/get-resolve-paths")
  10. const getTryExtensions = require("../util/get-try-extensions")
  11. const visitRequire = require("../util/visit-require")
  12. module.exports = {
  13. meta: {
  14. docs: {
  15. description:
  16. "disallow `require()` expressions which import extraneous modules",
  17. category: "Possible Errors",
  18. recommended: true,
  19. url:
  20. "https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-extraneous-require.md",
  21. },
  22. type: "problem",
  23. fixable: null,
  24. schema: [
  25. {
  26. type: "object",
  27. properties: {
  28. allowModules: getAllowModules.schema,
  29. convertPath: getConvertPath.schema,
  30. resolvePaths: getResolvePaths.schema,
  31. tryExtensions: getTryExtensions.schema,
  32. },
  33. additionalProperties: false,
  34. },
  35. ],
  36. },
  37. create(context) {
  38. const filePath = context.getFilename()
  39. if (filePath === "<input>") {
  40. return {}
  41. }
  42. return visitRequire(context, {}, targets => {
  43. checkExtraneous(context, filePath, targets)
  44. })
  45. },
  46. }