Skip to content

Commit

Permalink
[Fix] false positive for prefer-default-export with type export
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Oct 18, 2019
1 parent 112a0bf commit 15ba863
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/rules/prefer-default-export.js
Expand Up @@ -14,6 +14,7 @@ module.exports = {
let specifierExportCount = 0
let hasDefaultExport = false
let hasStarExport = false
let hasTypeExport = false
let namedExportNode = null

function captureDeclaration(identifierOrPattern) {
Expand Down Expand Up @@ -50,9 +51,6 @@ module.exports = {
// if there are specifiers, node.declaration should be null
if (!node.declaration) return

// don't warn on single type aliases, declarations, or interfaces
if (node.exportKind === 'type') return

const { type } = node.declaration

if (
Expand All @@ -61,6 +59,8 @@ module.exports = {
type === 'TSInterfaceDeclaration' ||
type === 'InterfaceDeclaration'
) {
specifierExportCount++
hasTypeExport = true
return
}

Expand All @@ -86,7 +86,7 @@ module.exports = {
},

'Program:exit': function() {
if (specifierExportCount === 1 && !hasDefaultExport && !hasStarExport) {
if (specifierExportCount === 1 && !hasDefaultExport && !hasStarExport && !hasTypeExport) {
context.report(namedExportNode, 'Prefer default export.')
}
},
Expand Down
9 changes: 8 additions & 1 deletion tests/src/rules/prefer-default-export.js
Expand Up @@ -3,7 +3,7 @@ import { test, getNonDefaultParsers } from '../utils'
import { RuleTester } from 'eslint'

const ruleTester = new RuleTester()
, rule = require('rules/prefer-default-export')
, rule = require('../../../src/rules/prefer-default-export')

ruleTester.run('prefer-default-export', rule, {
valid: [
Expand Down Expand Up @@ -194,6 +194,13 @@ context('TypeScript', function() {
},
parserConfig,
),
test (
{
code: 'export interface foo { bar: string; }; export function goo() {}',
parser,
},
parserConfig,
),
],
invalid: [],
})
Expand Down

0 comments on commit 15ba863

Please sign in to comment.