Skip to content

Instantly share code, notes, and snippets.

@mcloide
Created February 7, 2014 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcloide/e5f630901e1be4b9b128 to your computer and use it in GitHub Desktop.
Save mcloide/e5f630901e1be4b9b128 to your computer and use it in GitHub Desktop.
ESLint
function findVariable(name) {
var scope = context.getScope(),
scopeVariable = [];
function filter(variable) {
return variable.name === name;
}
scopeVariable = scope.variables.filter(filter);
if (scopeVariable.length === 0) {
if (!scope.upper) {
return null;
}
scope = scope.upper;
} else {
for (i = 0; i < scopeVariable.length; ++i) {
scopeVariable = scope.variables.filter(filter);
if (scopeVariable.length === 0) {
if (!scope.upper) {
return null;
}
scope = scope.upper;
}
}
}
return lookupVariable(scopeVariable[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment