Skip to content

Commit

Permalink
[Fix] no-named-as-default: correct error message
Browse files Browse the repository at this point in the history
The rule works for both exports and imports, so the message should be
precise about what the user did wrong.
  • Loading branch information
akwodkiewicz committed Sep 8, 2024
1 parent cd5e05c commit 9134b7b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/rules/no-named-as-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = {

context.report(
defaultSpecifier,
`Using exported name '${defaultSpecifier[nameKey].name}' as identifier for default export.`,
`Using exported name '${defaultSpecifier[nameKey].name}' as identifier for default ${nameKey === 'local' ? `import` : `export`}.`,
);

}
Expand Down
10 changes: 5 additions & 5 deletions tests/src/rules/no-named-as-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ ruleTester.run('no-named-as-default', rule, {
test({
code: 'import foo from "./bar";',
errors: [{
message: 'Using exported name \'foo\' as identifier for default export.',
message: 'Using exported name \'foo\' as identifier for default import.',
type: 'ImportDefaultSpecifier',
}],
}),
test({
code: 'import foo, { foo as bar } from "./bar";',
errors: [{
message: 'Using exported name \'foo\' as identifier for default export.',
message: 'Using exported name \'foo\' as identifier for default import.',
type: 'ImportDefaultSpecifier',
}],
}),
Expand Down Expand Up @@ -109,15 +109,15 @@ ruleTester.run('no-named-as-default', rule, {
testVersion('>= 8.7', () => ({
code: 'import foo from "./export-default-string-and-named"',
errors: [{
message: 'Using exported name \'foo\' as identifier for default export.',
message: 'Using exported name \'foo\' as identifier for default import.',
type: 'ImportDefaultSpecifier',
}],
parserOptions: { ecmaVersion: 2022 },
})),
testVersion('>= 8.7', () => ({
code: 'import foo, { foo as bar } from "./export-default-string-and-named"',
errors: [{
message: 'Using exported name \'foo\' as identifier for default export.',
message: 'Using exported name \'foo\' as identifier for default import.',
type: 'ImportDefaultSpecifier',
}],
parserOptions: { ecmaVersion: 2022 },
Expand All @@ -128,7 +128,7 @@ ruleTester.run('no-named-as-default', rule, {
test({
code: 'import variable from "./no-named-as-default/exports.js";',
errors: [{
message: 'Using exported name \'variable\' as identifier for default export.',
message: 'Using exported name \'variable\' as identifier for default import.',
type: 'ImportDefaultSpecifier',
}],
}),
Expand Down

0 comments on commit 9134b7b

Please sign in to comment.