no-unresolved.js 6.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict';
  2. var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
  3. var _ModuleCache = require('eslint-module-utils/ModuleCache');var _ModuleCache2 = _interopRequireDefault(_ModuleCache);
  4. var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
  5. var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };} /**
  6. * @fileOverview Ensures that an imported path exists, given resolution rules.
  7. * @author Ben Mosher
  8. */module.exports = { meta: {
  9. type: 'problem',
  10. docs: {
  11. url: (0, _docsUrl2['default'])('no-unresolved') },
  12. schema: [
  13. (0, _moduleVisitor.makeOptionsSchema)({
  14. caseSensitive: { type: 'boolean', 'default': true },
  15. caseSensitiveStrict: { type: 'boolean', 'default': false } })] },
  16. create: function () {function create(context) {
  17. var options = context.options[0] || {};
  18. function checkSourceValue(source, node) {
  19. // ignore type-only imports
  20. if (node.importKind === 'type') {
  21. return;
  22. }
  23. var caseSensitive = !_resolve.CASE_SENSITIVE_FS && options.caseSensitive !== false;
  24. var caseSensitiveStrict = !_resolve.CASE_SENSITIVE_FS && options.caseSensitiveStrict;
  25. var resolvedPath = (0, _resolve2['default'])(source.value, context);
  26. if (resolvedPath === undefined) {
  27. context.report(
  28. source, 'Unable to resolve path to module \'' + String(
  29. source.value) + '\'.');
  30. } else if (caseSensitive || caseSensitiveStrict) {
  31. var cacheSettings = _ModuleCache2['default'].getSettings(context.settings);
  32. if (!(0, _resolve.fileExistsWithCaseSync)(resolvedPath, cacheSettings, caseSensitiveStrict)) {
  33. context.report(
  34. source, 'Casing of ' + String(
  35. source.value) + ' does not match the underlying filesystem.');
  36. }
  37. }
  38. }
  39. return (0, _moduleVisitor2['default'])(checkSourceValue, options);
  40. }return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