Skip to content

Commit

Permalink
(#609) Make prefer-default-export count re-exported default exports
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Oct 11, 2016
1 parent 2b7e64f commit f9faaad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## [Unreleased]

### Fixed
- [`prefer-default-export`] handles re-exported default exports ([#609])

## [2.0.1] - 2016-10-06
### Fixed
Expand Down Expand Up @@ -399,6 +400,7 @@ for info on changes for earlier releases.
[#157]: https://github.com/benmosher/eslint-plugin-import/pull/157
[#314]: https://github.com/benmosher/eslint-plugin-import/pull/314

[#609]: https://github.com/benmosher/eslint-plugin-import/issues/609
[#604]: https://github.com/benmosher/eslint-plugin-import/issues/604
[#577]: https://github.com/benmosher/eslint-plugin-import/issues/577
[#570]: https://github.com/benmosher/eslint-plugin-import/issues/570
Expand Down
30 changes: 17 additions & 13 deletions src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,24 @@ module.exports = {
let hasStarExport = false
let namedExportNode = null

function captureDeclaration(identifierOrPattern) {
if (identifierOrPattern.type === 'ObjectPattern') {
// recursively capture
identifierOrPattern.properties
.forEach(function(property) {
captureDeclaration(property.value)
})
} else {
// assume it's a single standard identifier
specifierExportCount++
}
}

return {
'ExportDefaultSpecifier': function() {
specifierExportCount++
},

'ExportSpecifier': function(node) {
if (node.exported.name === 'default') {
hasDefaultExport = true
Expand All @@ -25,19 +42,6 @@ module.exports = {
// if there are specifiers, node.declaration should be null
if (!node.declaration) return

function captureDeclaration(identifierOrPattern) {
if (identifierOrPattern.type === 'ObjectPattern') {
// recursively capture
identifierOrPattern.properties
.forEach(function(property) {
captureDeclaration(property.value)
})
} else {
// assume it's a single standard identifier
specifierExportCount++
}
}

if (node.declaration.declarations) {
node.declaration.declarations.forEach(function(declaration) {
captureDeclaration(declaration.id)
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 @@ -55,6 +55,10 @@ ruleTester.run('prefer-default-export', rule, {
code: `
export * from './foo';`,
}),
test({
code: `export Memory, { MemoryValue } from './Memory'`,
parser: 'babel-eslint',
}),

// no exports at all
test({
Expand Down

0 comments on commit f9faaad

Please sign in to comment.