diff --git a/src/rules/no-deprecated.js b/src/rules/no-deprecated.js index 5556fa591..cc7f553d9 100644 --- a/src/rules/no-deprecated.js +++ b/src/rules/no-deprecated.js @@ -6,6 +6,7 @@ module.exports = function (context) { , namespaces = new Map() function checkSpecifiers(node) { + if (node.type !== 'ImportDeclaration') return if (node.source == null) return // local export, ignore const imports = Exports.get(node.source.value, context) @@ -64,7 +65,7 @@ module.exports = function (context) { } return { - 'ImportDeclaration': checkSpecifiers, + 'Program': ({ body }) => body.forEach(checkSpecifiers), 'Identifier': function (node) { if (node.parent.type === 'MemberExpression' && node.parent.property === node) { diff --git a/tests/src/rules/no-deprecated.js b/tests/src/rules/no-deprecated.js index 38fb817d9..92660348b 100644 --- a/tests/src/rules/no-deprecated.js +++ b/tests/src/rules/no-deprecated.js @@ -134,3 +134,25 @@ ruleTester.run('no-deprecated', rule, { }), ], }) + +ruleTester.run('no-deprecated: hoisting', rule, { + valid: [ + + test({ + code: "function x(deepDep) { console.log(deepDep.MY_TERRIBLE_ACTION) } import { deepDep } from './deep-deprecated'", + }), + + ], + + invalid: [ + + test({ + code: "console.log(MY_TERRIBLE_ACTION); import { MY_TERRIBLE_ACTION } from './deprecated'", + errors: [ + { type: 'Identifier', message: 'Deprecated: please stop sending/handling this action type.' }, + { type: 'ImportSpecifier', message: 'Deprecated: please stop sending/handling this action type.' }, + ], + }), + + ], +})