UNPKG

canonical

Version:

Canonical code style linter and formatter for JavaScript, SCSS, CSS and JSON.

32 lines (25 loc) 820 B
import Exports from '../core/getExports' module.exports = 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.hasDefault) { context.report(defaultSpecifier, 'No default export found in module.') } } return { 'ImportDeclaration': checkDefault.bind(null, 'ImportDefaultSpecifier'), 'ExportNamedDeclaration': checkDefault.bind(null, 'ExportDefaultSpecifier'), } }