-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
no-default-export.js
35 lines (31 loc) · 980 Bytes
/
no-default-export.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
module.exports = {
meta: {
docs: {},
},
create(context) {
// ignore non-modules
if (context.parserOptions.sourceType !== 'module') {
return {}
}
const preferNamed = 'Prefer named exports.'
const noAliasDefault = ({local}) =>
`Do not alias \`${local.name}\` as \`default\`. Just export ` +
`\`${local.name}\` itself instead.`
return {
ExportDefaultDeclaration(node) {
context.report({node, message: preferNamed})
},
ExportNamedDeclaration(node) {
node.specifiers.forEach(specifier => {
if (specifier.type === 'ExportDefaultSpecifier' &&
specifier.exported.name === 'default') {
context.report({node, message: preferNamed})
} else if (specifier.type === 'ExportSpecifier' &&
specifier.exported.name === 'default') {
context.report({node, message: noAliasDefault(specifier)})
}
})
},
}
},
}