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

[Fix] false positive for prefer-default-export with type export #1506

Merged
merged 1 commit into from Dec 5, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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