Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefer-default-export: Support 'export function foo() {}; export const x = 4;' #359

Merged
merged 2 commits into from
May 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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