Skip to content

Commit

Permalink
[fix] default: make error message less confusing
Browse files Browse the repository at this point in the history
Fixes #751, fixes #786
  • Loading branch information
golopot authored and ljharb committed Sep 4, 2019
1 parent 7ffbf03 commit 43172af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
16 changes: 7 additions & 9 deletions src/rules/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ module.exports = {

function checkDefault(specifierType, node) {

// poor man's Array.find
let defaultSpecifier
node.specifiers.some((n) => {
if (n.type === specifierType) {
defaultSpecifier = n
return true
}
})
const defaultSpecifier = node.specifiers.find(
specifier => specifier.type === specifierType
)

if (!defaultSpecifier) return
var imports = Exports.get(node.source.value, context)
Expand All @@ -29,7 +24,10 @@ module.exports = {
if (imports.errors.length) {
imports.reportErrors(context, node)
} else if (imports.get('default') === undefined) {
context.report(defaultSpecifier, 'No default export found in module.')
context.report({
node: defaultSpecifier,
message: `No default export found in imported module "${node.source.value}".`,
})
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/src/rules/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ruleTester.run('default', rule, {

test({
code: 'import baz from "./named-exports";',
errors: [{ message: 'No default export found in module.'
errors: [{ message: 'No default export found in imported module "./named-exports".'
, type: 'ImportDefaultSpecifier'}]}),

test({
Expand All @@ -114,29 +114,29 @@ ruleTester.run('default', rule, {
test({
code: 'export baz from "./named-exports"',
parser: require.resolve('babel-eslint'),
errors: ['No default export found in module.'],
errors: ['No default export found in imported module "./named-exports".'],
}),
test({
code: 'export baz, { bar } from "./named-exports"',
parser: require.resolve('babel-eslint'),
errors: ['No default export found in module.'],
errors: ['No default export found in imported module "./named-exports".'],
}),
test({
code: 'export baz, * as names from "./named-exports"',
parser: require.resolve('babel-eslint'),
errors: ['No default export found in module.'],
errors: ['No default export found in imported module "./named-exports".'],
}),
// exports default from a module with no default
test({
code: 'import twofer from "./broken-trampoline"',
parser: require.resolve('babel-eslint'),
errors: ['No default export found in module.'],
errors: ['No default export found in imported module "./broken-trampoline".'],
}),

// #328: * exports do not include default
test({
code: 'import barDefault from "./re-export"',
errors: [`No default export found in module.`],
errors: ['No default export found in imported module "./re-export".'],
}),
],
})
Expand All @@ -152,7 +152,7 @@ if (!CASE_SENSITIVE_FS) {
invalid: [
test({
code: 'import bar from "./Named-Exports"',
errors: ['No default export found in module.'],
errors: ['No default export found in imported module "./Named-Exports".'],
}),
],
})
Expand Down

0 comments on commit 43172af

Please sign in to comment.