Skip to content

Commit

Permalink
Fix: no-deprecated-api crash in self-assign (fixes #87)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jul 19, 2017
1 parent f1a137b commit 6422918
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/rules/no-deprecated-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ function create(context) {
const ignoredModuleItems = options.ignoreModuleItems || []
const ignoredGlobalItems = options.ignoreGlobalItems || []
let globalScope = null
const varStack = []

/**
* Reports a use of a deprecated API.
Expand Down Expand Up @@ -400,9 +401,16 @@ function create(context) {
* @returns {void}
*/
function checkVariable(variable, path, infoMap) {
if (varStack.indexOf(variable) !== -1) {
return
}
varStack.push(variable)

for (const reference of variable.references.filter(r => r.isRead())) {
checkProperties(reference.identifier, path, infoMap)
}

varStack.pop()
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/no-deprecated-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ ruleTester.run("no-deprecated-api", rule, {
env: {node: true},
options: [{ignoreIndirectDependencies: true}],
},

// https://github.com/mysticatea/eslint-plugin-node/issues/87
{
code: "let fs = fs || require(\"fs\")",
env: {node: true, es6: true},
},
],
invalid: [
//----------------------------------------------------------------------
Expand Down

0 comments on commit 6422918

Please sign in to comment.