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

[feat] default: make message less confusing #1470

Merged
merged 1 commit into from
Sep 4, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Added
- support `parseForESLint` from custom parser ([#1435], thanks [@JounQin])

### Fixed
- `default`: make error message less confusing ([#1470], thanks [@golopot])

## [2.18.2] - 2019-07-19
- Skip warning on type interfaces ([#1425], thanks [@lencioni])

Expand Down Expand Up @@ -601,6 +604,7 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#1470]: https://github.com/benmosher/eslint-plugin-import/pull/1470
[#1435]: https://github.com/benmosher/eslint-plugin-import/pull/1435
[#1425]: https://github.com/benmosher/eslint-plugin-import/pull/1425
[#1419]: https://github.com/benmosher/eslint-plugin-import/pull/1419
Expand Down
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