Skip to content

Commit 10fb144

Browse files
committed
no-deprecated: respect hoisting
1 parent 6abb7e1 commit 10fb144

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/rules/no-deprecated.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = function (context) {
66
, namespaces = new Map()
77

88
function checkSpecifiers(node) {
9+
if (node.type !== 'ImportDeclaration') return
910
if (node.source == null) return // local export, ignore
1011

1112
const imports = Exports.get(node.source.value, context)
@@ -64,7 +65,7 @@ module.exports = function (context) {
6465
}
6566

6667
return {
67-
'ImportDeclaration': checkSpecifiers,
68+
'Program': ({ body }) => body.forEach(checkSpecifiers),
6869

6970
'Identifier': function (node) {
7071
if (node.parent.type === 'MemberExpression' && node.parent.property === node) {

tests/src/rules/no-deprecated.js

+22
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,25 @@ ruleTester.run('no-deprecated', rule, {
134134
}),
135135
],
136136
})
137+
138+
ruleTester.run('no-deprecated: hoisting', rule, {
139+
valid: [
140+
141+
test({
142+
code: "function x(deepDep) { console.log(deepDep.MY_TERRIBLE_ACTION) } import { deepDep } from './deep-deprecated'",
143+
}),
144+
145+
],
146+
147+
invalid: [
148+
149+
test({
150+
code: "console.log(MY_TERRIBLE_ACTION); import { MY_TERRIBLE_ACTION } from './deprecated'",
151+
errors: [
152+
{ type: 'Identifier', message: 'Deprecated: please stop sending/handling this action type.' },
153+
{ type: 'ImportSpecifier', message: 'Deprecated: please stop sending/handling this action type.' },
154+
],
155+
}),
156+
157+
],
158+
})

0 commit comments

Comments
 (0)