-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
no-named-as-default.js
42 lines (34 loc) · 1.1 KB
/
no-named-as-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
42
import Exports from '../ExportMap'
import importDeclaration from '../importDeclaration'
import docsUrl from '../docsUrl'
module.exports = {
meta: {
type: 'problem',
docs: {
url: docsUrl('no-named-as-default'),
},
},
create: function (context) {
function checkDefault(nameKey, defaultSpecifier) {
// #566: default is a valid specifier
if (defaultSpecifier[nameKey].name === 'default') return
var declaration = importDeclaration(context)
var imports = Exports.get(declaration.source.value, context)
if (imports == null) return
if (imports.errors.length) {
imports.reportErrors(context, declaration)
return
}
if (imports.has('default') &&
imports.has(defaultSpecifier[nameKey].name)) {
context.report(defaultSpecifier,
'Using exported name \'' + defaultSpecifier[nameKey].name +
'\' as identifier for default export.')
}
}
return {
'ImportDefaultSpecifier': checkDefault.bind(null, 'local'),
'ExportDefaultSpecifier': checkDefault.bind(null, 'exported'),
}
},
}