зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset c88863b64010 (bug 1312355) for eslint bustage. r=backout
This commit is contained in:
Родитель
f137514b8d
Коммит
a8f157b8d8
|
@ -18,6 +18,7 @@ const { ADDON_SIGNING, REQUIRE_SIGNING } = CONSTANTS
|
|||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/AddonManager.jsm");
|
||||
/* globals AddonManagerPrivate*/
|
||||
Cu.import("resource://gre/modules/Preferences.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "AddonRepository",
|
||||
|
|
|
@ -70,7 +70,6 @@ const globalCache = new Map();
|
|||
*/
|
||||
function GlobalsForNode(path) {
|
||||
this.path = path;
|
||||
this.root = helpers.getRootDir(path);
|
||||
}
|
||||
|
||||
GlobalsForNode.prototype = {
|
||||
|
@ -93,8 +92,8 @@ GlobalsForNode.prototype = {
|
|||
|
||||
ExpressionStatement(node, parents) {
|
||||
let isGlobal = helpers.getIsGlobalScope(parents);
|
||||
let names = helpers.convertExpressionToGlobals(node, isGlobal, this.root);
|
||||
return names.map(name => { return { name, writable: true }});
|
||||
let name = helpers.convertExpressionToGlobal(node, isGlobal);
|
||||
return name ? [{ name, writable: true}] : [];
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@ var estraverse = require("estraverse");
|
|||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
||||
var modules = null;
|
||||
|
||||
var definitions = [
|
||||
/^loader\.lazyGetter\(this, "(\w+)"/,
|
||||
/^loader\.lazyImporter\(this, "(\w+)"/,
|
||||
|
@ -32,7 +30,7 @@ var definitions = [
|
|||
];
|
||||
|
||||
var imports = [
|
||||
/^(?:Cu|Components\.utils)\.import\(".*\/((.*?)\.jsm?)"(?:, this)?\)/,
|
||||
/^(?:Cu|Components\.utils)\.import\(".*\/(.*?)\.jsm?"(?:, this)?\)/,
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
|
@ -154,29 +152,23 @@ module.exports = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Attempts to convert an ExpressionStatement to likely global variable
|
||||
* definitions.
|
||||
* Attempts to convert an ExpressionStatement to a likely global variable
|
||||
* definition.
|
||||
*
|
||||
* @param {Object} node
|
||||
* The AST node to convert.
|
||||
* @param {boolean} isGlobal
|
||||
* True if the current node is in the global scope.
|
||||
* @param {String} repository
|
||||
* The root of the repository.
|
||||
* True if the current node is in the global scope
|
||||
*
|
||||
* @return {Array}
|
||||
* An array of variable names defined.
|
||||
* @return {String or null}
|
||||
* The variable name defined.
|
||||
*/
|
||||
convertExpressionToGlobals: function(node, isGlobal, repository) {
|
||||
if (!modules) {
|
||||
modules = require(path.join(repository, "tools", "lint", "eslint", "modules.json"));
|
||||
}
|
||||
|
||||
convertExpressionToGlobal: function(node, isGlobal) {
|
||||
try {
|
||||
var source = this.getASTSource(node);
|
||||
}
|
||||
catch (e) {
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
|
||||
for (var reg of definitions) {
|
||||
|
@ -184,10 +176,10 @@ module.exports = {
|
|||
if (match) {
|
||||
// Must be in the global scope
|
||||
if (!isGlobal) {
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
|
||||
return [match[1]];
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,18 +188,14 @@ module.exports = {
|
|||
if (match) {
|
||||
// The two argument form is only acceptable in the global scope
|
||||
if (node.expression.arguments.length > 1 && !isGlobal) {
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
|
||||
if (match[1] in modules) {
|
||||
return modules[match[1]];
|
||||
}
|
||||
|
||||
return [match[2]];
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -369,12 +357,13 @@ module.exports = {
|
|||
/**
|
||||
* Gets the root directory of the repository by walking up directories until
|
||||
* a .eslintignore file is found.
|
||||
* @param {String} fileName
|
||||
* The absolute path of a file in the repository
|
||||
* @param {ASTContext} context
|
||||
* The current context.
|
||||
*
|
||||
* @return {String} The absolute path of the repository directory
|
||||
*/
|
||||
getRootDir: function(fileName) {
|
||||
getRootDir: function(context) {
|
||||
var fileName = this.getAbsoluteFilePath(context);
|
||||
var dirName = path.dirname(fileName);
|
||||
|
||||
while (dirName && !fs.existsSync(path.join(dirName, ".eslintignore"))) {
|
||||
|
|
|
@ -60,8 +60,7 @@ module.exports = function(context) {
|
|||
return;
|
||||
}
|
||||
|
||||
let filepath = helpers.getAbsoluteFilePath(context);
|
||||
let root = helpers.getRootDir(filepath);
|
||||
let root = helpers.getRootDir(context);
|
||||
for (let script of SCRIPTS) {
|
||||
let fileName = path.join(root, script);
|
||||
try {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "eslint-plugin-mozilla",
|
||||
"version": "0.2.4",
|
||||
"version": "0.2.3",
|
||||
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
|
||||
"keywords": [
|
||||
"eslint",
|
||||
|
|
Загрузка…
Ссылка в новой задаче