Skip to content

Commit

Permalink
allow multiple named export through variable deconstructing fixes imp…
Browse files Browse the repository at this point in the history
  • Loading branch information
gavriguy committed May 19, 2016
1 parent c15901b commit e120b2e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/rules/prefer-default-export.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ export { foo, bar }
const foo = 'foo';
export { foo as default }
```

```javascript
// good5.js

// export multiple vars through deconstructing.
export const { foo, bar } = baz;
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"lodash.endswith": "^4.0.1",
"lodash.find": "^4.3.0",
"lodash.findindex": "^4.3.0",
"lodash.get": "4.3.0",
"object-assign": "^4.0.1",
"pkg-up": "^1.0.0"
}
Expand Down
10 changes: 9 additions & 1 deletion src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict'

import get from 'lodash.get'
// import forEach from 'lodash.forEach'

module.exports = function(context) {
let namedExportCount = 0
let specifierExportCount = 0
Expand All @@ -15,7 +18,12 @@ module.exports = function(context) {
}
},
'ExportNamedDeclaration': function(node) {
namedExportCount++
const properties = get(node, 'declaration.declarations[0].id.properties')
if (properties) {
namedExportCount = namedExportCount + properties.length
} else {
namedExportCount++
}
namedExportNode = node
},
'ExportDefaultDeclaration': function() {
Expand Down
13 changes: 13 additions & 0 deletions tests/src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ ruleTester.run('prefer-default-export', rule, {
code: `
export { foo as default }`,
}),
test({
code: `
export const { foo, bar } = baz;`,
}),

],
invalid: [
test({
Expand All @@ -44,5 +49,13 @@ ruleTester.run('prefer-default-export', rule, {
message: 'Prefer default export.',
}],
}),
test({
code: `
export const { foo } = baz;`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
}],
}),
],
})

0 comments on commit e120b2e

Please sign in to comment.