From 3636689d5a0ddfd982ad71858a12d6f67aadb39d Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 15 Aug 2023 13:18:20 -0700 Subject: [PATCH] [patch] `no-deprecated`: report on the imported specifier instead of the entire import statement This also makes error ordering more consistent since certain eslint/node combinations reverse the ordering --- CHANGELOG.md | 1 + lib/rules/no-deprecated.js | 2 +- tests/lib/rules/no-deprecated.js | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d76c5c6f7..c7ace5dd6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange * [`no-deprecated`]: prevent false positive on commonjs import ([#3614][] @akulsr0) * [`no-unsafe`]: report on the method instead of the entire component (@ljharb) * [`no-deprecated`]: report on the destructured property instead of the entire variable declarator (@ljharb) +* [`no-deprecated`]: report on the imported specifier instead of the entire import statement (@ljharb) [#3614]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3614 diff --git a/lib/rules/no-deprecated.js b/lib/rules/no-deprecated.js index 261c09b143..d37b55bbfd 100644 --- a/lib/rules/no-deprecated.js +++ b/lib/rules/no-deprecated.js @@ -226,7 +226,7 @@ module.exports = { return; } node.specifiers.filter(((s) => s.imported)).forEach((specifier) => { - checkDeprecation(node, `${MODULES[node.source.value][0]}.${specifier.imported.name}`); + checkDeprecation(node, `${MODULES[node.source.value][0]}.${specifier.imported.name}`, specifier); }); }, diff --git a/tests/lib/rules/no-deprecated.js b/tests/lib/rules/no-deprecated.js index cb9fb6a910..d986533aa5 100644 --- a/tests/lib/rules/no-deprecated.js +++ b/tests/lib/rules/no-deprecated.js @@ -533,7 +533,7 @@ ruleTester.run('no-deprecated', rule, { '18.0.0', 'createRoot', 'https://reactjs.org/link/switch-to-createroot', - { type: 'ImportDeclaration', line: 2, column: 9 } + { type: 'ImportSpecifier', line: 2, column: 18 } ), errorMessage( 'ReactDOM.render', @@ -555,7 +555,7 @@ ruleTester.run('no-deprecated', rule, { '18.0.0', 'hydrateRoot', 'https://reactjs.org/link/switch-to-createroot', - { type: 'ImportDeclaration', line: 2, column: 9 } + { type: 'ImportSpecifier', line: 2, column: 18 } ), errorMessage( 'ReactDOM.hydrate', @@ -577,7 +577,7 @@ ruleTester.run('no-deprecated', rule, { '18.0.0', 'root.unmount', 'https://reactjs.org/link/switch-to-createroot', - { type: 'ImportDeclaration', line: 2, column: 9 } + { type: 'ImportSpecifier', line: 2, column: 18 } ), errorMessage( 'ReactDOM.unmountComponentAtNode', @@ -599,7 +599,7 @@ ruleTester.run('no-deprecated', rule, { '18.0.0', 'renderToPipeableStream', 'https://reactjs.org/docs/react-dom-server.html#rendertonodestream', - { type: 'ImportDeclaration', line: 2, column: 9 } + { type: 'ImportSpecifier', line: 2, column: 18 } ), errorMessage( 'ReactDOMServer.renderToNodeStream',