Skip to content

Commit 9e3b46c

Browse files
committed
[Fix] no-named-as-default: correct error message
The rule works for both exports and imports, so the message should be precise about what the user did wrong.
1 parent 055eb13 commit 9e3b46c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/rules/no-named-as-default.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module.exports = {
7474

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

8080
}

tests/src/rules/no-named-as-default.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ ruleTester.run('no-named-as-default', rule, {
6767
test({
6868
code: 'import foo from "./bar";',
6969
errors: [{
70-
message: 'Using exported name \'foo\' as identifier for default export.',
70+
message: 'Using exported name \'foo\' as identifier for default import.',
7171
type: 'ImportDefaultSpecifier',
7272
}],
7373
}),
7474
test({
7575
code: 'import foo, { foo as bar } from "./bar";',
7676
errors: [{
77-
message: 'Using exported name \'foo\' as identifier for default export.',
77+
message: 'Using exported name \'foo\' as identifier for default import.',
7878
type: 'ImportDefaultSpecifier',
7979
}],
8080
}),
@@ -109,15 +109,15 @@ ruleTester.run('no-named-as-default', rule, {
109109
testVersion('>= 8.7', () => ({
110110
code: 'import foo from "./export-default-string-and-named"',
111111
errors: [{
112-
message: 'Using exported name \'foo\' as identifier for default export.',
112+
message: 'Using exported name \'foo\' as identifier for default import.',
113113
type: 'ImportDefaultSpecifier',
114114
}],
115115
parserOptions: { ecmaVersion: 2022 },
116116
})),
117117
testVersion('>= 8.7', () => ({
118118
code: 'import foo, { foo as bar } from "./export-default-string-and-named"',
119119
errors: [{
120-
message: 'Using exported name \'foo\' as identifier for default export.',
120+
message: 'Using exported name \'foo\' as identifier for default import.',
121121
type: 'ImportDefaultSpecifier',
122122
}],
123123
parserOptions: { ecmaVersion: 2022 },
@@ -128,7 +128,7 @@ ruleTester.run('no-named-as-default', rule, {
128128
test({
129129
code: 'import variable from "./no-named-as-default/exports.js";',
130130
errors: [{
131-
message: 'Using exported name \'variable\' as identifier for default export.',
131+
message: 'Using exported name \'variable\' as identifier for default import.',
132132
type: 'ImportDefaultSpecifier',
133133
}],
134134
}),

0 commit comments

Comments
 (0)