get-resolve-paths.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * @author Toru Nagashima
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. const DEFAULT_VALUE = Object.freeze([])
  7. /**
  8. * Gets `resolvePaths` property from a given option object.
  9. *
  10. * @param {object|undefined} option - An option object to get.
  11. * @returns {string[]|null} The `allowModules` value, or `null`.
  12. */
  13. function get(option) {
  14. if (option && option.resolvePaths && Array.isArray(option.resolvePaths)) {
  15. return option.resolvePaths.map(String)
  16. }
  17. return null
  18. }
  19. /**
  20. * Gets "resolvePaths" setting.
  21. *
  22. * 1. This checks `options` property, then returns it if exists.
  23. * 2. This checks `settings.node` property, then returns it if exists.
  24. * 3. This returns `[]`.
  25. *
  26. * @param {RuleContext} context - The rule context.
  27. * @returns {string[]} A list of extensions.
  28. */
  29. module.exports = function getResolvePaths(context, optionIndex = 0) {
  30. return (
  31. get(context.options && context.options[optionIndex]) ||
  32. get(context.settings && context.settings.node) ||
  33. DEFAULT_VALUE
  34. )
  35. }
  36. module.exports.schema = {
  37. type: "array",
  38. items: { type: "string" },
  39. uniqueItems: true,
  40. }