-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
default.js
40 lines (33 loc) · 1017 Bytes
/
default.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
import Exports from '../ExportMap'
import docsUrl from '../docsUrl'
module.exports = {
meta: {
type: 'problem',
docs: {
url: docsUrl('default'),
},
schema: [],
},
create: function (context) {
function checkDefault(specifierType, node) {
const defaultSpecifier = node.specifiers.find(
specifier => specifier.type === specifierType
)
if (!defaultSpecifier) return
var imports = Exports.get(node.source.value, context)
if (imports == null) return
if (imports.errors.length) {
imports.reportErrors(context, node)
} else if (imports.get('default') === undefined) {
context.report({
node: defaultSpecifier,
message: `No default export found in imported module "${node.source.value}".`,
})
}
}
return {
'ImportDeclaration': checkDefault.bind(null, 'ImportDefaultSpecifier'),
'ExportNamedDeclaration': checkDefault.bind(null, 'ExportDefaultSpecifier'),
}
},
}