Bug 1355778 - Manual fix of ESLint issues in eslint-plugin-* due to the rule changes. r?Mossop
MozReview-Commit-ID: Ieh4qkSORjW
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js
@@ -7,17 +7,16 @@
*/
"use strict";
const path = require("path");
const fs = require("fs");
const helpers = require("./helpers");
const escope = require("escope");
-const estraverse = require("estraverse");
/**
* Parses a list of "name:boolean_value" or/and "name" options divided by comma
* or whitespace.
*
* This function was copied from eslint.js
*
* @param {string} string The string to parse.
@@ -120,53 +119,53 @@ GlobalsForNode.prototype = {
};
module.exports = {
/**
* Returns all globals for a given file. Recursively searches through
* import-globals-from directives and also includes globals defined by
* standard eslint directives.
*
- * @param {String} path
+ * @param {String} filePath
* The absolute path of the file to be parsed.
* @return {Array}
* An array of objects that contain details about the globals:
* - {String} name
* The name of the global.
* - {Boolean} writable
* If the global is writeable or not.
*/
- getGlobalsForFile(path) {
- if (globalCache.has(path)) {
- return globalCache.get(path);
+ getGlobalsForFile(filePath) {
+ if (globalCache.has(filePath)) {
+ return globalCache.get(filePath);
}
- if (globalDiscoveryInProgressForFiles.has(path)) {
+ if (globalDiscoveryInProgressForFiles.has(filePath)) {
// We're already processing this file, so return an empty set for now -
// the initial processing will pick up on the globals for this file.
return [];
}
- globalDiscoveryInProgressForFiles.add(path);
+ globalDiscoveryInProgressForFiles.add(filePath);
- let content = fs.readFileSync(path, "utf8");
+ let content = fs.readFileSync(filePath, "utf8");
// Parse the content into an AST
let ast = helpers.getAST(content);
// Discover global declarations
let scopeManager = escope.analyze(ast);
let globalScope = scopeManager.acquire(ast);
let globals = Object.keys(globalScope.variables).map(v => ({
name: globalScope.variables[v].name,
writable: true
}));
// Walk over the AST to find any of our custom globals
- let handler = new GlobalsForNode(path);
+ let handler = new GlobalsForNode(filePath);
helpers.walkAST(ast, (type, node, parents) => {
// We have to discover any globals that ESLint would have defined through
// comment directives
if (type == "BlockComment") {
let value = node.value.trim();
value = value.replace(/\n/g, "");
let match = /^globals?\s+(.+)/.exec(value);
@@ -182,19 +181,19 @@ module.exports = {
}
if (type in handler) {
let newGlobals = handler[type](node, parents, globalScope);
globals.push.apply(globals, newGlobals);
}
});
- globalCache.set(path, globals);
+ globalCache.set(filePath, globals);
- globalDiscoveryInProgressForFiles.delete(path);
+ globalDiscoveryInProgressForFiles.delete(filePath);
return globals;
},
/**
* Intended to be used as-is for an ESLint rule that parses for globals in
* the current file and recurses through import-globals-from directives.
*
* @param {Object} context
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -1,17 +1,16 @@
/**
* @fileoverview A collection of helper functions.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
-var escope = require("escope");
var espree = require("espree");
var estraverse = require("estraverse");
var path = require("path");
var fs = require("fs");
var ini = require("ini-parser");
var modules = null;
var directoryManifests = new Map();
@@ -224,29 +223,29 @@ module.exports = {
try {
var source = this.getASTSource(node);
} catch (e) {
return [];
}
for (var reg of definitions) {
- var match = source.match(reg);
+ let match = source.match(reg);
if (match) {
// Must be in the global scope
if (!isGlobal) {
return [];
}
return [match[1]];
}
}
for (reg of imports) {
- var match = source.match(reg);
+ let match = source.match(reg);
if (match) {
// The two argument form is only acceptable in the global scope
if (node.expression.arguments.length > 1 && !isGlobal) {
return [];
}
if (match[1] in modules) {
return modules[match[1]];
@@ -567,12 +566,12 @@ module.exports = {
},
/**
* When ESLint is run from SublimeText, paths retrieved from
* context.getFileName contain leading and trailing double-quote characters.
* These characters need to be removed.
*/
- cleanUpPath(path) {
- return path.replace(/^"/, "").replace(/"$/, "");
+ cleanUpPath(pathName) {
+ return pathName.replace(/^"/, "").replace(/"$/, "");
}
};
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/avoid-nsISupportsString-preferences.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/avoid-nsISupportsString-preferences.js
@@ -8,18 +8,16 @@
*/
"use strict";
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
-var helpers = require("../helpers");
-
function isNsISupportsString(arg) {
let isNsISupportsStringIdentifier = obj =>
obj.type == "Identifier" && obj.name == "nsISupportsString";
return isNsISupportsStringIdentifier(arg) ||
(arg.type == "MemberExpression" &&
isNsISupportsStringIdentifier(arg.property));
}
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browser-window-globals.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browser-window-globals.js
@@ -10,17 +10,16 @@
"use strict";
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
var path = require("path");
var helpers = require("../helpers");
-var globals = require("../globals");
var browserWindowEnv = require("../environments/browser-window");
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------------
return {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-content-task-globals.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-content-task-globals.js
@@ -13,19 +13,17 @@
"use strict";
/* eslint max-len:"off" */
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
-var path = require("path");
var helpers = require("../helpers");
-var globals = require("../globals");
var frameScriptEnv = require("../environments/frame-script");
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------------
return {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js
@@ -9,17 +9,16 @@
"use strict";
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
var fs = require("fs");
-var path = require("path");
var helpers = require("../helpers");
var globals = require("../globals");
module.exports = function(context) {
function importHead(path, node) {
try {
let stats = fs.statSync(path);
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-import-into-var-and-global.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-import-into-var-and-global.js
@@ -12,18 +12,16 @@
*/
"use strict";
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
-var helpers = require("../helpers");
-
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
return {
"CallExpression": function(node) {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-single-arg-cu-import.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-single-arg-cu-import.js
@@ -7,18 +7,16 @@
*/
"use strict";
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
-var helpers = require("../helpers");
-
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
return {
"CallExpression": function(node) {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-useless-parameters.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-useless-parameters.js
@@ -8,18 +8,16 @@
*/
"use strict";
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
-var helpers = require("../helpers");
-
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
return {
"CallExpression": function(node) {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-useless-removeEventListener.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-useless-removeEventListener.js
@@ -8,18 +8,16 @@
*/
"use strict";
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
-var helpers = require("../helpers");
-
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
return {
"CallExpression": function(node) {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-importGlobalProperties.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-importGlobalProperties.js
@@ -7,18 +7,16 @@
*/
"use strict";
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
-var helpers = require("../helpers");
-
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
return {
"CallExpression": function(node) {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-default-preference-values.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-default-preference-values.js
@@ -8,18 +8,16 @@
*/
"use strict";
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
-var helpers = require("../helpers");
-
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
return {
"TryStatement": function(node) {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-ownerGlobal.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-ownerGlobal.js
@@ -7,18 +7,16 @@
*/
"use strict";
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
-var helpers = require("../helpers");
-
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
return {
"MemberExpression": function(node) {
--- a/tools/lint/eslint/eslint-plugin-mozilla/package.json
+++ b/tools/lint/eslint/eslint-plugin-mozilla/package.json
@@ -1,11 +1,11 @@
{
"name": "eslint-plugin-mozilla",
- "version": "0.2.36",
+ "version": "0.2.37",
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin",
"mozilla",
"firefox"
],