get-resolve-paths.js 1.5 KB

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