Skip to content

Commit

Permalink
[Fix] prefer-default-export: Skips warning on a single type declara…
Browse files Browse the repository at this point in the history
…tion or type alias.

Fixes #1332.
  • Loading branch information
sharmilajesupaul authored and ljharb committed Jun 10, 2019
1 parent 6512110 commit 53f79e6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ module.exports = {
// if there are specifiers, node.declaration should be null
if (!node.declaration) return

// don't count flow types exports
// don't warn on single type aliases or declarations
if (node.exportKind === 'type') return

if (node.declaration.type === 'TSTypeAliasDeclaration'
|| node.declaration.type === 'TypeAlias') return

if (node.declaration.declarations) {
node.declaration.declarations.forEach(function(declaration) {
captureDeclaration(declaration.id)
Expand Down
47 changes: 46 additions & 1 deletion tests/src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ruleTester.run('prefer-default-export', rule, {
test({
code: `export type UserId = number;`,
parser: require.resolve('babel-eslint'),
}),
}),

// issue #653
test({
Expand All @@ -84,6 +84,51 @@ ruleTester.run('prefer-default-export', rule, {
parser: require.resolve('babel-eslint'),
}),

// Exporting types
test({
code: `
export type foo = string;
export type bar = number;`,
parser: require.resolve('typescript-eslint-parser'),
}),
test({
code: `
export type foo = string;
export type bar = number;`,
parser: require.resolve('babel-eslint'),
}),
test({
code: 'export type foo = string',
parser: require.resolve('typescript-eslint-parser'),
}),
test({
code: 'export type foo = string',
parser: require.resolve('babel-eslint'),
}),
test({
code: `
type foo = 'foo';
export { foo };`,
parser: require.resolve('typescript-eslint-parser'),
}),
test({
code: `
type foo = 'foo';
export { foo };`,
parser: require.resolve('babel-eslint'),
}),
test({
code: `
type foo = 'foo';
export { foo as bar };`,
parser: require.resolve('typescript-eslint-parser'),
}),
test({
code: `
type foo = 'foo';
export { foo as bar };`,
parser: require.resolve('babel-eslint'),
}),
// ...SYNTAX_CASES,
],
invalid: [
Expand Down

0 comments on commit 53f79e6

Please sign in to comment.