From 9134b7ba31511bd80015861ce212764e73ff7569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20W=C3=B3dkiewicz?= Date: Sun, 8 Sep 2024 21:41:45 +0200 Subject: [PATCH] [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. --- src/rules/no-named-as-default.js | 2 +- tests/src/rules/no-named-as-default.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rules/no-named-as-default.js b/src/rules/no-named-as-default.js index b18fa9f05..d4b5c3ab1 100644 --- a/src/rules/no-named-as-default.js +++ b/src/rules/no-named-as-default.js @@ -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`}.`, ); } diff --git a/tests/src/rules/no-named-as-default.js b/tests/src/rules/no-named-as-default.js index 3f01414f1..f19648386 100644 --- a/tests/src/rules/no-named-as-default.js +++ b/tests/src/rules/no-named-as-default.js @@ -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', }], }), @@ -109,7 +109,7 @@ 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 }, @@ -117,7 +117,7 @@ ruleTester.run('no-named-as-default', rule, { 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 }, @@ -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', }], }),