-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
no-unresolved.js
49 lines (38 loc) · 1.36 KB
/
no-unresolved.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* @fileOverview Ensures that an imported path exists, given resolution rules.
* @author Ben Mosher
*/
import resolve, { CASE_SENSITIVE_FS, fileExistsWithCaseSync } from 'eslint-module-utils/resolve'
import ModuleCache from 'eslint-module-utils/ModuleCache'
import moduleVisitor, { makeOptionsSchema } from 'eslint-module-utils/moduleVisitor'
import docsUrl from '../docsUrl'
module.exports = {
meta: {
type: 'problem',
docs: {
url: docsUrl('no-unresolved'),
},
schema: [ makeOptionsSchema({
caseSensitive: { type: 'boolean', default: true },
})],
},
create: function (context) {
function checkSourceValue(source) {
const shouldCheckCase = !CASE_SENSITIVE_FS &&
(!context.options[0] || context.options[0].caseSensitive !== false)
const resolvedPath = resolve(source.value, context)
if (resolvedPath === undefined) {
context.report(source,
`Unable to resolve path to module '${source.value}'.`)
}
else if (shouldCheckCase) {
const cacheSettings = ModuleCache.getSettings(context.settings)
if (!fileExistsWithCaseSync(resolvedPath, cacheSettings)) {
context.report(source,
`Casing of ${source.value} does not match the underlying filesystem.`)
}
}
}
return moduleVisitor(checkSourceValue, context.options[0])
},
}