Path: blob/main/src/rules/no-unresolved.js
829 views
/**1* @fileOverview Ensures that an imported path exists, given resolution rules.2* @author Ben Mosher3*/45import resolve, { CASE_SENSITIVE_FS, fileExistsWithCaseSync } from 'eslint-module-utils/resolve';6import ModuleCache from 'eslint-module-utils/ModuleCache';7import moduleVisitor, { makeOptionsSchema } from 'eslint-module-utils/moduleVisitor';8import docsUrl from '../docsUrl';910module.exports = {11meta: {12type: 'problem',13docs: {14url: docsUrl('no-unresolved'),15},1617schema: [18makeOptionsSchema({19caseSensitive: { type: 'boolean', default: true },20caseSensitiveStrict: { type: 'boolean', default: false },21}),22],23},2425create(context) {26const options = context.options[0] || {};2728function checkSourceValue(source, node) {29// ignore type-only imports30if (node.importKind === 'type') {31return;32}3334const caseSensitive = !CASE_SENSITIVE_FS && options.caseSensitive !== false;35const caseSensitiveStrict = !CASE_SENSITIVE_FS && options.caseSensitiveStrict;3637const resolvedPath = resolve(source.value, context);3839if (resolvedPath === undefined) {40context.report(41source,42`Unable to resolve path to module '${source.value}'.`,43);44} else if (caseSensitive || caseSensitiveStrict) {45const cacheSettings = ModuleCache.getSettings(context.settings);46if (!fileExistsWithCaseSync(resolvedPath, cacheSettings, caseSensitiveStrict)) {47context.report(48source,49`Casing of ${source.value} does not match the underlying filesystem.`,50);51}52}53}5455return moduleVisitor(checkSourceValue, options);56},57};585960