Skip to content

Commit

Permalink
prefer-default-export: Support 'export function foo() {}; export cons…
Browse files Browse the repository at this point in the history
…t x = 4;' (#359)

* prefer-default-export: Add tests and else case

* Add changelog message for #359
  • Loading branch information
scottnonnenberg authored and benmosher committed May 31, 2016
1 parent edb57ce commit 92f7d65
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## TBD
### Fixed
- [`prefer-default-export`] handles `export function` and `export const` in same file ([#359], thanks [@scottnonnenberg])

## resolvers/webpack/0.2.5 - 2016-05-23
### Added
- Added support for multiple webpack configs ([#181], thanks [@GreenGremlin])
Expand Down Expand Up @@ -225,6 +229,7 @@ for info on changes for earlier releases.
[`no-mutable-exports`]: ./docs/rules/no-mutable-exports.md
[`prefer-default-export`]: ./docs/rules/prefer-default-export.md

[#359]: https://github.com/benmosher/eslint-plugin-import/pull/359
[#343]: https://github.com/benmosher/eslint-plugin-import/pull/343
[#332]: https://github.com/benmosher/eslint-plugin-import/pull/332
[#322]: https://github.com/benmosher/eslint-plugin-import/pull/322
Expand Down
4 changes: 4 additions & 0 deletions src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ module.exports = function(context) {
captureDeclaration(declaration.id)
})
}
else {
// captures 'export function foo() {}' syntax
specifierExportCount++
}

namedExportNode = node
},
Expand Down
17 changes: 17 additions & 0 deletions tests/src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ ruleTester.run('prefer-default-export', rule, {
export const foo = 'foo';
export const bar = 'bar';`,
}),
test({
code: `
export default function bar() {};`,
}),
test({
code: `
export const foo = 'foo';
export function bar() {};`,
}),
test({
code: `
export const foo = 'foo';
Expand Down Expand Up @@ -56,6 +65,14 @@ ruleTester.run('prefer-default-export', rule, {
// ...SYNTAX_CASES,
],
invalid: [
test({
code: `
export function bar() {};`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
}],
}),
test({
code: `
export const foo = 'foo';`,
Expand Down

0 comments on commit 92f7d65

Please sign in to comment.