diff --git a/src/rules/prefer-default-export.js b/src/rules/prefer-default-export.js index 871cd8187..5d41d59bc 100644 --- a/src/rules/prefer-default-export.js +++ b/src/rules/prefer-default-export.js @@ -15,7 +15,15 @@ module.exports = function(context) { } }, 'ExportNamedDeclaration': function(node) { - namedExportCount++ + if (node.declaration && + node.declaration.declarations.length && + node.declaration.declarations[0].id.type === 'ObjectPattern') { + + namedExportCount += node.declaration.declarations[0].id.properties.length + } else { + namedExportCount++ + } + namedExportNode = node }, 'ExportDefaultDeclaration': function() { @@ -23,7 +31,7 @@ module.exports = function(context) { }, 'Program:exit': function() { - if (namedExportCount === 1 && specifierExportCount < 2 && !hasDefaultExport) { + if (namedExportCount === 1 && specifierExportCount < 2 && !hasDefaultExport) { context.report(namedExportNode, 'Prefer default export.') } }, diff --git a/tests/src/rules/prefer-default-export.js b/tests/src/rules/prefer-default-export.js index c3827eeba..354d91423 100644 --- a/tests/src/rules/prefer-default-export.js +++ b/tests/src/rules/prefer-default-export.js @@ -21,6 +21,10 @@ ruleTester.run('prefer-default-export', rule, { code: ` export { foo, bar }`, }), + test({ + code: ` + export const { foo, bar } = item;`, + }), test({ code: ` export { foo as default }`,