Skip to content

Commit c787026

Browse files
jfmengelsbenmosher
authored andcommitted
(#609) Make prefer-default-export count re-exported default exports
1 parent 2b7e64f commit c787026

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

Diff for: CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).
55

66
## [Unreleased]
7-
7+
### Fixed
8+
- [`prefer-default-export`] handles re-exported default exports ([#609])
89

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

403+
[#609]: https://github.com/benmosher/eslint-plugin-import/issues/609
402404
[#604]: https://github.com/benmosher/eslint-plugin-import/issues/604
403405
[#577]: https://github.com/benmosher/eslint-plugin-import/issues/577
404406
[#570]: https://github.com/benmosher/eslint-plugin-import/issues/570

Diff for: src/rules/prefer-default-export.js

+17-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,24 @@ module.exports = {
1111
let hasStarExport = false
1212
let namedExportNode = null
1313

14+
function captureDeclaration(identifierOrPattern) {
15+
if (identifierOrPattern.type === 'ObjectPattern') {
16+
// recursively capture
17+
identifierOrPattern.properties
18+
.forEach(function(property) {
19+
captureDeclaration(property.value)
20+
})
21+
} else {
22+
// assume it's a single standard identifier
23+
specifierExportCount++
24+
}
25+
}
26+
1427
return {
28+
'ExportDefaultSpecifier': function() {
29+
specifierExportCount++
30+
},
31+
1532
'ExportSpecifier': function(node) {
1633
if (node.exported.name === 'default') {
1734
hasDefaultExport = true
@@ -25,19 +42,6 @@ module.exports = {
2542
// if there are specifiers, node.declaration should be null
2643
if (!node.declaration) return
2744

28-
function captureDeclaration(identifierOrPattern) {
29-
if (identifierOrPattern.type === 'ObjectPattern') {
30-
// recursively capture
31-
identifierOrPattern.properties
32-
.forEach(function(property) {
33-
captureDeclaration(property.value)
34-
})
35-
} else {
36-
// assume it's a single standard identifier
37-
specifierExportCount++
38-
}
39-
}
40-
4145
if (node.declaration.declarations) {
4246
node.declaration.declarations.forEach(function(declaration) {
4347
captureDeclaration(declaration.id)

Diff for: tests/src/rules/prefer-default-export.js

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ ruleTester.run('prefer-default-export', rule, {
5555
code: `
5656
export * from './foo';`,
5757
}),
58+
test({
59+
code: `export Memory, { MemoryValue } from './Memory'`,
60+
parser: 'babel-eslint',
61+
}),
5862

5963
// no exports at all
6064
test({

0 commit comments

Comments
 (0)