Skip to content

Commit

Permalink
no-deprecated: respect hoisting
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Mar 11, 2016
1 parent 6abb7e1 commit 10fb144
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rules/no-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions tests/src/rules/no-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.' },
],
}),

],
})

0 comments on commit 10fb144

Please sign in to comment.