-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
default.js
41 lines (34 loc) · 1012 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
41
import Exports from '../ExportMap'
import docsUrl from '../docsUrl'
module.exports = {
meta: {
type: 'problem',
docs: {
url: docsUrl('default'),
},
},
create: function (context) {
function checkDefault(specifierType, node) {
// poor man's Array.find
let defaultSpecifier
node.specifiers.some((n) => {
if (n.type === specifierType) {
defaultSpecifier = n
return true
}
})
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(defaultSpecifier, 'No default export found in module.')
}
}
return {
'ImportDeclaration': checkDefault.bind(null, 'ImportDefaultSpecifier'),
'ExportNamedDeclaration': checkDefault.bind(null, 'ExportDefaultSpecifier'),
}
},
}