Skip to content

Commit

Permalink
[patch] no-deprecated: report on the imported specifier instead of …
Browse files Browse the repository at this point in the history
…the entire import statement

This also makes error ordering more consistent since certain eslint/node combinations reverse the ordering
  • Loading branch information
ljharb committed Aug 15, 2023
1 parent f9e4fa9 commit 3636689
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
},

Expand Down
8 changes: 4 additions & 4 deletions tests/lib/rules/no-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit 3636689

Please sign in to comment.