-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathdefault.js
40 lines (35 loc) · 1.14 KB
/
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 ExportMapBuilder from '../exportMap/builder';
import docsUrl from '../docsUrl';
module.exports = {
meta: {
type: 'problem',
docs: {
category: 'Static analysis',
description: 'Ensure a default export is present, given a default import.',
url: docsUrl('default'),
},
schema: [],
},
create(context) {
function checkDefault(specifierType, node) {
const defaultSpecifier = node.specifiers.find(
(specifier) => specifier.type === specifierType,
);
if (!defaultSpecifier) { return; }
const imports = ExportMapBuilder.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'),
};
},
};