Skip to content

Commit

Permalink
prefer-default-export: count destructured exports
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg committed May 15, 2016
1 parent a0401e2 commit b377fc6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@ 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() {
hasDefaultExport = true
},

'Program:exit': function() {
if (namedExportCount === 1 && specifierExportCount < 2 && !hasDefaultExport) {
if (namedExportCount === 1 && specifierExportCount < 2 && !hasDefaultExport) {
context.report(namedExportNode, 'Prefer default export.')
}
},
Expand Down
4 changes: 4 additions & 0 deletions tests/src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }`,
Expand Down

0 comments on commit b377fc6

Please sign in to comment.