Skip to content

Commit 6422918

Browse files
committed
Fix: no-deprecated-api crash in self-assign (fixes #87)
1 parent f1a137b commit 6422918

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/rules/no-deprecated-api.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ function create(context) {
193193
const ignoredModuleItems = options.ignoreModuleItems || []
194194
const ignoredGlobalItems = options.ignoreGlobalItems || []
195195
let globalScope = null
196+
const varStack = []
196197

197198
/**
198199
* Reports a use of a deprecated API.
@@ -400,9 +401,16 @@ function create(context) {
400401
* @returns {void}
401402
*/
402403
function checkVariable(variable, path, infoMap) {
404+
if (varStack.indexOf(variable) !== -1) {
405+
return
406+
}
407+
varStack.push(variable)
408+
403409
for (const reference of variable.references.filter(r => r.isRead())) {
404410
checkProperties(reference.identifier, path, infoMap)
405411
}
412+
413+
varStack.pop()
406414
}
407415

408416
/**

tests/lib/rules/no-deprecated-api.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ ruleTester.run("no-deprecated-api", rule, {
152152
env: {node: true},
153153
options: [{ignoreIndirectDependencies: true}],
154154
},
155+
156+
// https://github.com/mysticatea/eslint-plugin-node/issues/87
157+
{
158+
code: "let fs = fs || require(\"fs\")",
159+
env: {node: true, es6: true},
160+
},
155161
],
156162
invalid: [
157163
//----------------------------------------------------------------------

0 commit comments

Comments
 (0)