Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/eslint-plugin-import
Path: blob/main/src/rules/default.js
829 views
1
import Exports from '../ExportMap';
2
import docsUrl from '../docsUrl';
3
4
module.exports = {
5
meta: {
6
type: 'problem',
7
docs: {
8
url: docsUrl('default'),
9
},
10
schema: [],
11
},
12
13
create(context) {
14
15
function checkDefault(specifierType, node) {
16
17
const defaultSpecifier = node.specifiers.find(
18
specifier => specifier.type === specifierType,
19
);
20
21
if (!defaultSpecifier) return;
22
const imports = Exports.get(node.source.value, context);
23
if (imports == null) return;
24
25
if (imports.errors.length) {
26
imports.reportErrors(context, node);
27
} else if (imports.get('default') === undefined) {
28
context.report({
29
node: defaultSpecifier,
30
message: `No default export found in imported module "${node.source.value}".`,
31
});
32
}
33
}
34
35
return {
36
'ImportDeclaration': checkDefault.bind(null, 'ImportDefaultSpecifier'),
37
'ExportNamedDeclaration': checkDefault.bind(null, 'ExportDefaultSpecifier'),
38
};
39
},
40
};
41
42