• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

benmosher / eslint-plugin-import / #28399486

31 Aug 2017 08:48AM UTC coverage: 0.0% (-71.0%) from 71.019%
#28399486

push

ljharb
Handle unresolved js import when type is exported with the same name

0 of 1985 branches covered (0.0%)

0 of 8 new or added lines in 2 files covered. (0.0%)

2289 existing lines in 51 files now uncovered.

0 of 3012 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/core/importType.js
1
import { isAbsolute as nodeIsAbsolute, relative, resolve as nodeResolve } from 'path';
2
import isCoreModule from 'is-core-module';
3

4
import resolve from 'eslint-module-utils/resolve';
5
import { getContextPackagePath } from './packagePath';
6

7
function baseModule(name) {
UNCOV
8
  if (isScoped(name)) {
×
UNCOV
9
    const [scope, pkg] = name.split('/');
×
UNCOV
10
    return `${scope}/${pkg}`;
×
11
  }
UNCOV
12
  const [pkg] = name.split('/');
×
UNCOV
13
  return pkg;
×
14
}
15

16
export function isAbsolute(name) {
UNCOV
17
  return nodeIsAbsolute(name);
×
18
}
19

20
// path is defined only when a resolver resolves to a non-standard path
21
export function isBuiltIn(name, settings, path) {
UNCOV
22
  if (path || !name) return false;
×
UNCOV
23
  const base = baseModule(name);
×
UNCOV
24
  const extras = (settings && settings['import/core-modules']) || [];
×
UNCOV
25
  return isCoreModule(base) || extras.indexOf(base) > -1;
×
26
}
27

28
export function isExternalModule(name, settings, path, context) {
UNCOV
29
  if (arguments.length < 4) {
×
UNCOV
30
    throw new TypeError('isExternalModule: name, settings, path, and context are all required');
×
31
  }
UNCOV
32
  return isModule(name) && isExternalPath(name, settings, path, getContextPackagePath(context));
×
33
}
34

35
export function isExternalModuleMain(name, settings, path, context) {
UNCOV
36
  return isModuleMain(name) && isExternalPath(name, settings, path, getContextPackagePath(context));
×
37
}
38

39
function isExternalPath(name, settings, path, packagePath) {
UNCOV
40
  const internalScope = (settings && settings['import/internal-regex']);
×
UNCOV
41
  if (internalScope && new RegExp(internalScope).test(name)) {
×
UNCOV
42
    return false;
×
43
  }
44

UNCOV
45
  if (!path || relative(packagePath, path).startsWith('..')) {
×
UNCOV
46
    return true;
×
47
  }
48

UNCOV
49
  const folders = (settings && settings['import/external-module-folders']) || ['node_modules'];
×
UNCOV
50
  return folders.some((folder) => {
×
UNCOV
51
    const folderPath = nodeResolve(packagePath, folder);
×
UNCOV
52
    const relativePath = relative(folderPath, path);
×
UNCOV
53
    return !relativePath.startsWith('..');
×
54
  });
55
}
56

UNCOV
57
const moduleRegExp = /^\w/;
×
58
function isModule(name) {
UNCOV
59
  return name && moduleRegExp.test(name);
×
60
}
61

UNCOV
62
const moduleMainRegExp = /^[\w]((?!\/).)*$/;
×
63
function isModuleMain(name) {
UNCOV
64
  return name && moduleMainRegExp.test(name);
×
65
}
66

UNCOV
67
const scopedRegExp = /^@[^/]*\/?[^/]+/;
×
68
export function isScoped(name) {
UNCOV
69
  return name && scopedRegExp.test(name);
×
70
}
71

UNCOV
72
const scopedMainRegExp = /^@[^/]+\/?[^/]+$/;
×
73
export function isScopedMain(name) {
UNCOV
74
  return name && scopedMainRegExp.test(name);
×
75
}
76

77
function isRelativeToParent(name) {
UNCOV
78
  return/^\.\.$|^\.\.[\\/]/.test(name);
×
79
}
80

UNCOV
81
const indexFiles = ['.', './', './index', './index.js'];
×
82
function isIndex(name) {
UNCOV
83
  return indexFiles.indexOf(name) !== -1;
×
84
}
85

86
function isRelativeToSibling(name) {
UNCOV
87
  return /^\.[\\/]/.test(name);
×
88
}
89

90
function typeTest(name, context, path) {
UNCOV
91
  const { settings } = context;
×
UNCOV
92
  if (isAbsolute(name, settings, path)) { return 'absolute'; }
×
UNCOV
93
  if (isBuiltIn(name, settings, path)) { return 'builtin'; }
×
UNCOV
94
  if (isModule(name, settings, path) || isScoped(name, settings, path)) {
×
UNCOV
95
    const packagePath = getContextPackagePath(context);
×
UNCOV
96
    return isExternalPath(name, settings, path, packagePath) ? 'external' : 'internal';
×
97
  }
UNCOV
98
  if (isRelativeToParent(name, settings, path)) { return 'parent'; }
×
UNCOV
99
  if (isIndex(name, settings, path)) { return 'index'; }
×
UNCOV
100
  if (isRelativeToSibling(name, settings, path)) { return 'sibling'; }
×
UNCOV
101
  return 'unknown';
×
102
}
103

104
export function isScopedModule(name) {
UNCOV
105
  return name.indexOf('@') === 0 && !name.startsWith('@/');
×
106
}
107

108
export default function resolveImportType(name, context) {
UNCOV
109
  return typeTest(name, context, resolve(name, context));
×
110
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc