From c5078addd9e35fb20f25376148de65de760a5977 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 16 Jul 2019 23:15:22 -0700 Subject: [PATCH] [Refactor] `importType`: remove use of `cond` Using normal JS makes for far more understandable and maintainable code. --- src/core/importType.js | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/core/importType.js b/src/core/importType.js index 7755bb4a2..b948ea2bb 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -1,13 +1,8 @@ -import cond from 'lodash/cond' import coreModules from 'resolve/lib/core' import { join } from 'path' import resolve from 'eslint-module-utils/resolve' -function constant(value) { - return () => value -} - function baseModule(name) { if (isScoped(name)) { const [scope, pkg] = name.split('/') @@ -76,17 +71,17 @@ function isRelativeToSibling(name) { return /^\.[\\/]/.test(name) } -const typeTest = cond([ - [isAbsolute, constant('absolute')], - [isBuiltIn, constant('builtin')], - [isInternalModule, constant('internal')], - [isExternalModule, constant('external')], - [isScoped, constant('external')], - [isRelativeToParent, constant('parent')], - [isIndex, constant('index')], - [isRelativeToSibling, constant('sibling')], - [constant(true), constant('unknown')], -]) +function typeTest(name, settings, path) { + if (isAbsolute(name, settings, path)) { return 'absolute' } + if (isBuiltIn(name, settings, path)) { return 'builtin' } + if (isInternalModule(name, settings, path)) { return 'internal' } + if (isExternalModule(name, settings, path)) { return 'external' } + if (isScoped(name, settings, path)) { return 'external' } + if (isRelativeToParent(name, settings, path)) { return 'parent' } + if (isIndex(name, settings, path)) { return 'index' } + if (isRelativeToSibling(name, settings, path)) { return 'sibling' } + return 'unknown' +} export default function resolveImportType(name, context) { return typeTest(name, context.settings, resolve(name, context))