node/tools/eslint/lib/rules/no-implicit-globals.js
silverwind d9b8758f47 tools: update ESLint to 2.7.0
PR-URL: https://github.com/nodejs/node/pull/6132
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: thefourtheye <thechargingvolcano@gmail.com>
2016-04-20 16:24:21 -07:00

47 lines
1.5 KiB
JavaScript

/**
* @fileoverview Rule to check for implicit global variables and functions.
* @author Joshua Peek
* @copyright 2015 Joshua Peek. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = function(context) {
return {
"Program": function() {
var scope = context.getScope();
scope.variables.forEach(function(variable) {
if (variable.writeable) {
return;
}
variable.defs.forEach(function(def) {
if (def.type === "FunctionName" || (def.type === "Variable" && def.parent.kind === "var")) {
context.report(def.node, "Implicit global variable, assign as global property instead.");
}
});
});
scope.implicit.variables.forEach(function(variable) {
var scopeVariable = scope.set.get(variable.name);
if (scopeVariable && scopeVariable.writeable) {
return;
}
variable.defs.forEach(function(def) {
context.report(def.node, "Implicit global variable, assign as global property instead.");
});
});
}
};
};
module.exports.schema = [];