web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

  1. 'use strict'
  2. exports.__esModule = true
  3. const extname = require('path').extname
  4. const log = require('debug')('eslint-plugin-import:utils:ignore')
  5. // one-shot memoized
  6. let cachedSet, lastSettings
  7. function validExtensions(context) {
  8. if (cachedSet && context.settings === lastSettings) {
  9. return cachedSet
  10. }
  11. lastSettings = context.settings
  12. cachedSet = makeValidExtensionSet(context.settings)
  13. return cachedSet
  14. }
  15. function makeValidExtensionSet(settings) {
  16. // start with explicit JS-parsed extensions
  17. const exts = new Set(settings['import/extensions'] || [ '.js' ])
  18. // all alternate parser extensions are also valid
  19. if ('import/parsers' in settings) {
  20. for (let parser in settings['import/parsers']) {
  21. const parserSettings = settings['import/parsers'][parser]
  22. if (!Array.isArray(parserSettings)) {
  23. throw new TypeError('"settings" for ' + parser + ' must be an array')
  24. }
  25. parserSettings.forEach(ext => exts.add(ext))
  26. }
  27. }
  28. return exts
  29. }
  30. exports.getFileExtensions = makeValidExtensionSet
  31. exports.default = function ignore(path, context) {
  32. // check extension whitelist first (cheap)
  33. if (!hasValidExtension(path, context)) return true
  34. if (!('import/ignore' in context.settings)) return false
  35. const ignoreStrings = context.settings['import/ignore']
  36. for (let i = 0; i < ignoreStrings.length; i++) {
  37. const regex = new RegExp(ignoreStrings[i])
  38. if (regex.test(path)) {
  39. log(`ignoring ${path}, matched pattern /${ignoreStrings[i]}/`)
  40. return true
  41. }
  42. }
  43. return false
  44. }
  45. function hasValidExtension(path, context) {
  46. return validExtensions(context).has(extname(path))
  47. }
  48. exports.hasValidExtension = hasValidExtension