--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js
@@ -7,17 +7,17 @@ module.exports = {
"mozilla/import-headjs-globals": "warn",
"mozilla/mark-test-function-used": "warn"
},
"env": {
"browser": true,
"mozilla/browser-window": true,
"mozilla/simpletest": true
- //"node": true
+ // "node": true
},
"plugins": [
"mozilla"
],
// All globals made available in the test environment.
"globals": {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/chrome-worker.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/chrome-worker.js
@@ -5,18 +5,18 @@
*
* 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 globals = require('globals');
-var util = require('util');
+var globals = require("globals");
+var util = require("util");
var workerGlobals = util._extend({
ctypes: false
}, globals.worker);
module.exports = {
globals: workerGlobals
};
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js
@@ -41,17 +41,17 @@ function parseBooleanConfig(string, comm
let value;
if (pos !== -1) {
value = name.substring(pos + 1, name.length);
name = name.substring(0, pos);
}
items[name] = {
value: (value === "true"),
- comment: comment
+ comment
};
});
return items;
}
/**
* Global discovery can require parsing many files. This map of
@@ -138,19 +138,18 @@ module.exports = {
if (globalCache.has(path)) {
return globalCache.get(path);
}
if (globalDiscoveryInProgressForFiles.has(path)) {
// 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 [];
- } else {
- globalDiscoveryInProgressForFiles.add(path);
}
+ globalDiscoveryInProgressForFiles.add(path);
let content = fs.readFileSync(path, "utf8");
// Parse the content into an AST
let ast = helpers.getAST(content);
// Discover global declarations
let scopeManager = escope.analyze(ast);
@@ -164,17 +163,17 @@ module.exports = {
// Walk over the AST to find any of our custom globals
let handler = new GlobalsForNode(path);
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, '');
+ value = value.replace(/\n/g, "");
let match = /^globals?\s+(.+)/.exec(value);
if (match) {
let values = parseBooleanConfig(match[1].trim(), node);
for (let name of Object.keys(values)) {
globals.push({
name,
writable: values[name].value
});
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -46,34 +46,34 @@ module.exports = {
* in sourceText.
*
* @param {String} sourceText
* Text containing valid JavaScript.
*
* @return {Object}
* The resulting AST.
*/
- getAST: function(sourceText) {
+ getAST(sourceText) {
// Use a permissive config file to allow parsing of anything that Espree
// can parse.
var config = this.getPermissiveConfig();
return espree.parse(sourceText, config);
},
/**
* A simplistic conversion of some AST nodes to a standard string form.
*
* @param {Object} node
* The AST node to convert.
*
* @return {String}
* The JS source for the node.
*/
- getASTSource: function(node) {
+ getASTSource(node) {
switch (node.type) {
case "MemberExpression":
if (node.computed) {
throw new Error("getASTSource unsupported computed MemberExpression");
}
return this.getASTSource(node.object) + "." +
this.getASTSource(node.property);
case "ThisExpression":
@@ -174,17 +174,17 @@ module.exports = {
*
* @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.
*/
- convertWorkerExpressionToGlobals: function(node, isGlobal, repository,
+ convertWorkerExpressionToGlobals(node, isGlobal, repository,
dirname) {
var getGlobalsForFile = require("./globals").getGlobalsForFile;
if (!modules) {
modules = require(path.join(repository,
"tools", "lint", "eslint", "modules.json"));
}
@@ -211,17 +211,17 @@ module.exports = {
}
}
}
}
return results;
},
- convertExpressionToGlobals: function(node, isGlobal, repository) {
+ convertExpressionToGlobals(node, isGlobal, repository) {
if (!modules) {
modules = require(path.join(repository,
"tools", "lint", "eslint", "modules.json"));
}
try {
var source = this.getASTSource(node);
} catch (e) {
@@ -265,17 +265,17 @@ module.exports = {
*
* @param {String} name
* The variable name to add to the scope.
* @param {ASTScope} scope
* The scope to add to.
* @param {boolean} writable
* Whether the global can be overwritten.
*/
- addVarToScope: function(name, scope, writable) {
+ addVarToScope(name, scope, writable) {
scope.__defineGeneric(name, scope.set, scope.variables, null, null);
let variable = scope.set.get(name);
variable.eslintExplicitGlobal = false;
variable.writeable = writable;
// Walk to the global scope which holds all undeclared variables.
while (scope.type != "global") {
@@ -299,28 +299,28 @@ module.exports = {
/**
* Adds a set of globals to a scope.
*
* @param {Array} globalVars
* An array of global variable names.
* @param {ASTScope} scope
* The scope.
*/
- addGlobals: function(globalVars, scope) {
+ addGlobals(globalVars, scope) {
globalVars.forEach(v => this.addVarToScope(v.name, scope, v.writable));
},
/**
* To allow espree to parse almost any JavaScript we need as many features as
* possible turned on. This method returns that config.
*
* @return {Object}
* Espree compatible permissive config.
*/
- getPermissiveConfig: function() {
+ getPermissiveConfig() {
return {
range: true,
loc: true,
comment: true,
attachComment: true,
ecmaVersion: 8,
sourceType: "script",
ecmaFeatures: {
@@ -334,17 +334,17 @@ module.exports = {
* Check whether the context is the global scope.
*
* @param {Array} ancestors
* The parents of the current node.
*
* @return {Boolean}
* True or false
*/
- getIsGlobalScope: function(ancestors) {
+ getIsGlobalScope(ancestors) {
for (let parent of ancestors) {
if (parent.type == "FunctionExpression" ||
parent.type == "FunctionDeclaration") {
return false;
}
}
return true;
},
@@ -354,33 +354,33 @@ module.exports = {
*
* @param {RuleContext} scope
* You should pass this from within a rule
* e.g. helpers.getIsHeadFile(context)
*
* @return {Boolean}
* True or false
*/
- getIsHeadFile: function(scope) {
+ getIsHeadFile(scope) {
var pathAndFilename = this.cleanUpPath(scope.getFilename());
return /.*[\\/]head(_.+)?\.js$/.test(pathAndFilename);
},
/**
* Gets the head files for a potential test file
*
* @param {RuleContext} scope
* You should pass this from within a rule
* e.g. helpers.getIsHeadFile(context)
*
* @return {String[]}
* Paths to head files to load for the test
*/
- getTestHeadFiles: function(scope) {
+ getTestHeadFiles(scope) {
if (!this.getIsTest(scope)) {
return [];
}
let filepath = this.cleanUpPath(scope.getFilename());
let dir = path.dirname(filepath);
let names =
@@ -394,31 +394,31 @@ module.exports = {
* Gets all the test manifest data for a directory
*
* @param {String} dir
* The directory
*
* @return {Array}
* An array of objects with file and manifest properties
*/
- getManifestsForDirectory: function(dir) {
+ getManifestsForDirectory(dir) {
if (directoryManifests.has(dir)) {
return directoryManifests.get(dir);
}
let manifests = [];
let names = fs.readdirSync(dir);
for (let name of names) {
if (!name.endsWith(".ini")) {
continue;
}
try {
- let manifest = ini.parse(fs.readFileSync(path.join(dir, name), 'utf8'));
+ let manifest = ini.parse(fs.readFileSync(path.join(dir, name), "utf8"));
manifests.push({
file: path.join(dir, name),
manifest
});
} catch (e) {
}
}
@@ -432,17 +432,17 @@ module.exports = {
*
* @param {RuleContext} scope
* You should pass this from within a rule
* e.g. helpers.getIsHeadFile(context)
*
* @return {String}
* The path to the test manifest file
*/
- getTestManifest: function(scope) {
+ getTestManifest(scope) {
let filepath = this.cleanUpPath(scope.getFilename());
let dir = path.dirname(filepath);
let filename = path.basename(filepath);
for (let manifest of this.getManifestsForDirectory(dir)) {
if (filename in manifest.manifest) {
return manifest.file;
@@ -457,17 +457,17 @@ module.exports = {
*
* @param {RuleContext} scope
* You should pass this from within a rule
* e.g. helpers.getIsTest(context)
*
* @return {Boolean}
* True or false
*/
- getIsTest: function(scope) {
+ getIsTest(scope) {
// Regardless of the manifest name being in a manifest means we're a test.
let manifest = this.getTestManifest(scope);
if (manifest) {
return true;
}
return !!this.getTestType(scope);
},
@@ -477,17 +477,17 @@ module.exports = {
*
* @param {RuleContext} scope
* You should pass this from within a rule
* e.g. helpers.getIsHeadFile(context)
*
* @return {String or null}
* Test type: xpcshell, browser, chrome, mochitest
*/
- getTestType: function(scope) {
+ getTestType(scope) {
let manifest = this.getTestManifest(scope);
if (manifest) {
let name = path.basename(manifest);
for (let testType of ["browser", "xpcshell", "chrome", "mochitest"]) {
if (name.startsWith(testType)) {
return testType;
}
}
@@ -502,31 +502,31 @@ module.exports = {
if (filename.startsWith("test_")) {
return "xpcshell";
}
return null;
},
- getIsWorker: function(filePath) {
+ getIsWorker(filePath) {
let filename = path.basename(this.cleanUpPath(filePath)).toLowerCase();
return filename.includes("worker");
},
/**
* 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
*
* @return {String} The absolute path of the repository directory
*/
- getRootDir: function(fileName) {
+ getRootDir(fileName) {
var dirName = path.dirname(fileName);
while (dirName && !fs.existsSync(path.join(dirName, ".eslintignore"))) {
dirName = path.dirname(dirName);
}
if (!dirName) {
throw new Error("Unable to find root of repository");
@@ -540,39 +540,39 @@ module.exports = {
* repository, or from a directory in the repository when, for instance,
* executed by a text editor's plugin.
* The value returned by context.getFileName() varies because of this.
* This helper function makes sure to return an absolute file path for the
* current context, by looking at process.cwd().
* @param {Context} context
* @return {String} The absolute path
*/
- getAbsoluteFilePath: function(context) {
+ getAbsoluteFilePath(context) {
var fileName = this.cleanUpPath(context.getFilename());
var cwd = process.cwd();
if (path.isAbsolute(fileName)) {
// Case 2: executed from the repo's root with mach:
// fileName: /path/to/mozilla/repo/a/b/c/d.js
// cwd: /path/to/mozilla/repo
return fileName;
} else if (path.basename(fileName) == fileName) {
// Case 1b: executed from a nested directory, fileName is the base name
// without any path info (happens in Atom with linter-eslint)
return path.join(cwd, fileName);
- } else {
+ }
// Case 1: executed form in a nested directory, e.g. from a text editor:
// fileName: a/b/c/d.js
// cwd: /path/to/mozilla/repo/a/b/c
- var dirName = path.dirname(fileName);
- return cwd.slice(0, cwd.length - dirName.length) + fileName;
- }
+ var dirName = path.dirname(fileName);
+ return cwd.slice(0, cwd.length - dirName.length) + fileName;
+
},
/**
* 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: function(path) {
+ cleanUpPath(path) {
return path.replace(/^"/, "").replace(/"$/, "");
}
};
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
@@ -3,19 +3,19 @@
* standard and avoid common errors in the Mozilla project.
* 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";
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Plugin Definition
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
module.exports = {
configs: {
"browser-test": require("../lib/configs/browser-test"),
"chrome-test": require("../lib/configs/chrome-test"),
"mochitest-test": require("../lib/configs/mochitest-test"),
"recommended": require("../lib/configs/recommended"),
"xpcshell-test": require("../lib/configs/xpcshell-test")
},
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/processors/xbl-bindings.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/processors/xbl-bindings.js
@@ -48,17 +48,17 @@ function XMLParser(parser) {
comments: []
};
this._currentNode = this.document;
}
XMLParser.prototype = {
parser: null,
- onOpenTag: function(tag) {
+ onOpenTag(tag) {
let node = {
parentNode: this._currentNode,
local: tag.local,
namespace: tag.uri,
attributes: {},
children: [],
comments: [],
textContent: "",
@@ -72,40 +72,40 @@ XMLParser.prototype = {
node.attributes[attr] = tag.attributes[attr].value;
}
}
this._currentNode.children.push(node);
this._currentNode = node;
},
- onCloseTag: function(tagname) {
+ onCloseTag(tagname) {
this._currentNode.textEndLine = this.parser.line;
this._currentNode = this._currentNode.parentNode;
},
- addText: function(text) {
+ addText(text) {
this._currentNode.textContent += text;
},
- onText: function(text) {
+ onText(text) {
// Replace entities with some valid JS token.
this.addText(text.replace(entityRegex, "null"));
},
- onOpenCDATA: function() {
+ onOpenCDATA() {
// Turn the CDATA opening tag into whitespace for indent alignment
this.addText(" ".repeat("<![CDATA[".length));
},
- onCDATA: function(text) {
+ onCDATA(text) {
this.addText(text);
},
- onComment: function(text) {
+ onComment(text) {
this._currentNode.comments.push(text);
}
};
// -----------------------------------------------------------------------------
// Processor Definition
// -----------------------------------------------------------------------------
@@ -189,17 +189,17 @@ function addNodeLines(node, reindent) {
}
scriptLines.push(line);
startLine++;
}
}
module.exports = {
- preprocess: function(text, filename) {
+ preprocess(text, filename) {
xmlParseError = null;
scriptLines = [];
lineMap = [];
// Non-strict allows us to ignore many errors from entities and
// preprocessing at the expense of failing to report some XML errors.
// Unfortunately it also throws away the case of tagnames and attributes
let parser = sax.parser(false, {
@@ -350,17 +350,17 @@ module.exports = {
addSyntheticLine(indent(1) + `},`, binding.textEndLine);
}
addSyntheticLine(`};`, bindings.textEndLine);
let script = scriptLines.join("\n") + "\n";
return [script];
},
- postprocess: function(messages, filename) {
+ postprocess(messages, filename) {
// If there was an XML parse error then just return that
if (xmlParseError) {
return [xmlParseError];
}
// For every message from every script block update the line to point to the
// correct place.
let errors = [];
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/balanced-listeners.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/balanced-listeners.js
@@ -1,138 +1,138 @@
-/**
- * @fileoverview Check that there's a removeEventListener for each
- * addEventListener and an off for each on.
- * Note that for now, this rule is rather simple in that it only checks that
- * for each event name there is both an add and remove listener. It doesn't
- * check that these are called on the right objects or with the same callback.
- *
- * 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";
-
-// -----------------------------------------------------------------------------
-// Rule Definition
-// -----------------------------------------------------------------------------
-
-module.exports = function(context) {
- // ---------------------------------------------------------------------------
- // Helpers
- // ---------------------------------------------------------------------------
-
- var DICTIONARY = {
- "addEventListener": "removeEventListener",
- "on": "off"
- };
- // Invert this dictionary to make it easy later.
- var INVERTED_DICTIONARY = {};
- for (var i in DICTIONARY) {
- INVERTED_DICTIONARY[DICTIONARY[i]] = i;
- }
-
- // Collect the add/remove listeners in these 2 arrays.
- var addedListeners = [];
- var removedListeners = [];
-
- function addAddedListener(node) {
- var capture = false;
- let options = node.arguments[2];
- if (options) {
- if (options.type == "ObjectExpression") {
- if (options.properties.some(p => p.key.name == "once" &&
- p.value.value === true)) {
- // No point in adding listeners using the 'once' option.
- return;
- }
- capture = options.properties.some(p => p.key.name == "capture" &&
- p.value.value === true);
- } else {
- capture = options.value;
- }
- }
- addedListeners.push({
- functionName: node.callee.property.name,
- type: node.arguments[0].value,
- node: node.callee.property,
- useCapture: capture
- });
- }
-
- function addRemovedListener(node) {
- var capture = false;
- let options = node.arguments[2];
- if (options) {
- if (options.type == "ObjectExpression") {
- capture = options.properties.some(p => p.key.name == "capture" &&
- p.value.value === true);
- } else {
- capture = options.value;
- }
- }
- removedListeners.push({
- functionName: node.callee.property.name,
- type: node.arguments[0].value,
- useCapture: capture
- });
- }
-
- function getUnbalancedListeners() {
- var unbalanced = [];
-
- for (var j = 0; j < addedListeners.length; j++) {
- if (!hasRemovedListener(addedListeners[j])) {
- unbalanced.push(addedListeners[j]);
- }
- }
- addedListeners = removedListeners = [];
-
- return unbalanced;
- }
-
- function hasRemovedListener(addedListener) {
- for (var k = 0; k < removedListeners.length; k++) {
- var listener = removedListeners[k];
- if (DICTIONARY[addedListener.functionName] === listener.functionName &&
- addedListener.type === listener.type &&
- addedListener.useCapture === listener.useCapture) {
- return true;
- }
- }
-
- return false;
- }
-
- // ---------------------------------------------------------------------------
- // Public
- // ---------------------------------------------------------------------------
-
- return {
- CallExpression: function(node) {
- if (node.arguments.length === 0) {
- return;
- }
-
- if (node.callee.type === "MemberExpression") {
- var listenerMethodName = node.callee.property.name;
-
- if (DICTIONARY.hasOwnProperty(listenerMethodName)) {
- addAddedListener(node);
- } else if (INVERTED_DICTIONARY.hasOwnProperty(listenerMethodName)) {
- addRemovedListener(node);
- }
- }
- },
-
- "Program:exit": function() {
- getUnbalancedListeners().forEach(function(listener) {
- context.report(listener.node,
- "No corresponding '{{functionName}}({{type}})' was found.",
- {
- functionName: DICTIONARY[listener.functionName],
- type: listener.type
- });
- });
- }
- };
-};
+/**
+ * @fileoverview Check that there's a removeEventListener for each
+ * addEventListener and an off for each on.
+ * Note that for now, this rule is rather simple in that it only checks that
+ * for each event name there is both an add and remove listener. It doesn't
+ * check that these are called on the right objects or with the same callback.
+ *
+ * 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";
+
+// -----------------------------------------------------------------------------
+// Rule Definition
+// -----------------------------------------------------------------------------
+
+module.exports = function(context) {
+ // ---------------------------------------------------------------------------
+ // Helpers
+ // ---------------------------------------------------------------------------
+
+ var DICTIONARY = {
+ "addEventListener": "removeEventListener",
+ "on": "off"
+ };
+ // Invert this dictionary to make it easy later.
+ var INVERTED_DICTIONARY = {};
+ for (var i in DICTIONARY) {
+ INVERTED_DICTIONARY[DICTIONARY[i]] = i;
+ }
+
+ // Collect the add/remove listeners in these 2 arrays.
+ var addedListeners = [];
+ var removedListeners = [];
+
+ function addAddedListener(node) {
+ var capture = false;
+ let options = node.arguments[2];
+ if (options) {
+ if (options.type == "ObjectExpression") {
+ if (options.properties.some(p => p.key.name == "once" &&
+ p.value.value === true)) {
+ // No point in adding listeners using the 'once' option.
+ return;
+ }
+ capture = options.properties.some(p => p.key.name == "capture" &&
+ p.value.value === true);
+ } else {
+ capture = options.value;
+ }
+ }
+ addedListeners.push({
+ functionName: node.callee.property.name,
+ type: node.arguments[0].value,
+ node: node.callee.property,
+ useCapture: capture
+ });
+ }
+
+ function addRemovedListener(node) {
+ var capture = false;
+ let options = node.arguments[2];
+ if (options) {
+ if (options.type == "ObjectExpression") {
+ capture = options.properties.some(p => p.key.name == "capture" &&
+ p.value.value === true);
+ } else {
+ capture = options.value;
+ }
+ }
+ removedListeners.push({
+ functionName: node.callee.property.name,
+ type: node.arguments[0].value,
+ useCapture: capture
+ });
+ }
+
+ function getUnbalancedListeners() {
+ var unbalanced = [];
+
+ for (var j = 0; j < addedListeners.length; j++) {
+ if (!hasRemovedListener(addedListeners[j])) {
+ unbalanced.push(addedListeners[j]);
+ }
+ }
+ addedListeners = removedListeners = [];
+
+ return unbalanced;
+ }
+
+ function hasRemovedListener(addedListener) {
+ for (var k = 0; k < removedListeners.length; k++) {
+ var listener = removedListeners[k];
+ if (DICTIONARY[addedListener.functionName] === listener.functionName &&
+ addedListener.type === listener.type &&
+ addedListener.useCapture === listener.useCapture) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ // ---------------------------------------------------------------------------
+ // Public
+ // ---------------------------------------------------------------------------
+
+ return {
+ CallExpression(node) {
+ if (node.arguments.length === 0) {
+ return;
+ }
+
+ if (node.callee.type === "MemberExpression") {
+ var listenerMethodName = node.callee.property.name;
+
+ if (DICTIONARY.hasOwnProperty(listenerMethodName)) {
+ addAddedListener(node);
+ } else if (INVERTED_DICTIONARY.hasOwnProperty(listenerMethodName)) {
+ addRemovedListener(node);
+ }
+ }
+ },
+
+ "Program:exit": function() {
+ getUnbalancedListeners().forEach(function(listener) {
+ context.report(listener.node,
+ "No corresponding '{{functionName}}({{type}})' was found.",
+ {
+ functionName: DICTIONARY[listener.functionName],
+ type: listener.type
+ });
+ });
+ }
+ };
+};
--- 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
@@ -19,17 +19,17 @@ var globals = require("../globals");
var browserWindowEnv = require("../environments/browser-window");
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------------
return {
- Program: function(node) {
+ Program(node) {
let filePath = helpers.getAbsoluteFilePath(context);
let relativePath = path.relative(helpers.getRootDir(filePath), filePath);
if (browserWindowEnv.browserjsScripts &&
browserWindowEnv.browserjsScripts.includes(relativePath)) {
for (let global in browserWindowEnv.globals) {
helpers.addVarToScope(global, context.getScope(),
browserWindowEnv.globals[global]);
--- 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
@@ -34,16 +34,16 @@ module.exports = function(context) {
helpers.addGlobals(newGlobals, context.getScope());
}
// ---------------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------------
return {
- Program: function(node) {
+ Program(node) {
let heads = helpers.getTestHeadFiles(context);
for (let head of heads) {
importHead(head, node);
}
}
};
};
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-test-function-used.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-test-function-used.js
@@ -17,21 +17,21 @@
var helpers = require("../helpers");
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------------
return {
- Program: function() {
+ Program() {
if (helpers.getTestType(context) == "browser") {
context.markVariableAsUsed("test");
return;
}
if (helpers.getTestType(context) == "xpcshell") {
context.markVariableAsUsed("run_test");
- return;
+
}
}
};
};
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-aArgs.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-aArgs.js
@@ -1,55 +1,55 @@
-/**
- * @fileoverview warns against using hungarian notation in function arguments
- * (i.e. aArg).
- *
- * 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";
-
-// -----------------------------------------------------------------------------
-// Rule Definition
-// -----------------------------------------------------------------------------
-
-module.exports = function(context) {
- // ---------------------------------------------------------------------------
- // Helpers
- // ---------------------------------------------------------------------------
-
- function isPrefixed(name) {
- return name.length >= 2 && /^a[A-Z]/.test(name);
- }
-
- function deHungarianize(name) {
- return name.substring(1, 2).toLowerCase() +
- name.substring(2, name.length);
- }
-
- function checkFunction(node) {
- for (var i = 0; i < node.params.length; i++) {
- var param = node.params[i];
- if (param.name && isPrefixed(param.name)) {
- var errorObj = {
- name: param.name,
- suggestion: deHungarianize(param.name)
- };
- context.report(param,
- "Parameter '{{name}}' uses Hungarian Notation, " +
- "consider using '{{suggestion}}' instead.",
- errorObj);
- }
- }
- }
-
- // ---------------------------------------------------------------------------
- // Public
- // ---------------------------------------------------------------------------
-
- return {
- "FunctionDeclaration": checkFunction,
- "ArrowFunctionExpression": checkFunction,
- "FunctionExpression": checkFunction
- };
-};
+/**
+ * @fileoverview warns against using hungarian notation in function arguments
+ * (i.e. aArg).
+ *
+ * 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";
+
+// -----------------------------------------------------------------------------
+// Rule Definition
+// -----------------------------------------------------------------------------
+
+module.exports = function(context) {
+ // ---------------------------------------------------------------------------
+ // Helpers
+ // ---------------------------------------------------------------------------
+
+ function isPrefixed(name) {
+ return name.length >= 2 && /^a[A-Z]/.test(name);
+ }
+
+ function deHungarianize(name) {
+ return name.substring(1, 2).toLowerCase() +
+ name.substring(2, name.length);
+ }
+
+ function checkFunction(node) {
+ for (var i = 0; i < node.params.length; i++) {
+ var param = node.params[i];
+ if (param.name && isPrefixed(param.name)) {
+ var errorObj = {
+ name: param.name,
+ suggestion: deHungarianize(param.name)
+ };
+ context.report(param,
+ "Parameter '{{name}}' uses Hungarian Notation, " +
+ "consider using '{{suggestion}}' instead.",
+ errorObj);
+ }
+ }
+ }
+
+ // ---------------------------------------------------------------------------
+ // Public
+ // ---------------------------------------------------------------------------
+
+ return {
+ "FunctionDeclaration": checkFunction,
+ "ArrowFunctionExpression": checkFunction,
+ "FunctionExpression": checkFunction
+ };
+};
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js
@@ -30,17 +30,17 @@ module.exports = function(context) {
// ---------------------------------------------------------------------------
function showError(node, identifier) {
if (isInContentTask) {
return;
}
context.report({
- node: node,
+ node,
message: identifier +
" is a possible Cross Process Object Wrapper (CPOW)."
});
}
function isContentTask(node) {
return node &&
node.type === "MemberExpression" &&
@@ -50,29 +50,29 @@ module.exports = function(context) {
node.object.name === "ContentTask";
}
// ---------------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------------
return {
- CallExpression: function(node) {
+ CallExpression(node) {
if (isContentTask(node.callee)) {
isInContentTask = true;
}
},
"CallExpression:exit": function(node) {
if (isContentTask(node.callee)) {
isInContentTask = false;
}
},
- MemberExpression: function(node) {
+ MemberExpression(node) {
if (helpers.getTestType(context) != "browser") {
return;
}
var expression = context.getSource(node);
// Only report a single CPOW error per node -- so if checking
// |cpows| reports one, don't report another below.
@@ -81,32 +81,32 @@ module.exports = function(context) {
showError(node, expression);
return true;
}
return false;
});
if (!someCpowFound && helpers.getIsGlobalScope(context.getAncestors())) {
if (/^content\./.test(expression)) {
showError(node, expression);
- return;
+
}
}
},
- Identifier: function(node) {
+ Identifier(node) {
if (helpers.getTestType(context) != "browser") {
return;
}
var expression = context.getSource(node);
if (expression == "content" || /^content\./.test(expression)) {
if (node.parent.type === "MemberExpression" &&
node.parent.object &&
node.parent.object.type === "Identifier" &&
node.parent.object.name != "content") {
return;
}
showError(node, expression);
- return;
+
}
}
};
};
--- a/tools/lint/eslint/eslint-plugin-mozilla/tests/avoid-nsISupportsString-preferences.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/avoid-nsISupportsString-preferences.js
@@ -1,27 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Requirements
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
var rule = require("../lib/rules/avoid-nsISupportsString-preferences");
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Tests
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
function invalidCode(code, accessType = "get") {
let message = "use " + accessType + "StringPref instead of " +
accessType + "ComplexValue with nsISupportsString";
- return {code: code, errors: [{message: message, type: "CallExpression"}]};
+ return {code, errors: [{message, type: "CallExpression"}]};
}
exports.runTest = function(ruleTester) {
ruleTester.run("no-useless-removeEventListener", rule, {
valid: [
"branch.getStringPref('name');",
"branch.getComplexValue('name', Ci.nsIPrefLocalizedString);",
"branch.setStringPref('name', 'blah');",
--- a/tools/lint/eslint/eslint-plugin-mozilla/tests/avoid-removeChild.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/avoid-removeChild.js
@@ -1,29 +1,29 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Requirements
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
var rule = require("../lib/rules/avoid-removeChild");
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Tests
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
function invalidCode(code, message) {
if (!message) {
message = "use element.remove() instead of " +
"element.parentNode.removeChild(element)";
}
- return {code: code, errors: [{message: message, type: "CallExpression"}]};
+ return {code, errors: [{message, type: "CallExpression"}]};
}
exports.runTest = function(ruleTester) {
ruleTester.run("no-useless-removeEventListener", rule, {
valid: [
"elt.remove();",
"elt.parentNode.parentNode.removeChild(elt2.parentNode);",
"elt.parentNode.removeChild(elt2);",
--- a/tools/lint/eslint/eslint-plugin-mozilla/tests/balanced-listeners.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/balanced-listeners.js
@@ -1,27 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Requirements
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
var rule = require("../lib/rules/balanced-listeners");
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Tests
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
function error(code, message) {
return {
- code: code,
- errors: [{message: message, type: "Identifier"}]
+ code,
+ errors: [{message, type: "Identifier"}]
};
}
exports.runTest = function(ruleTester) {
ruleTester.run("balanced-listeners", rule, {
valid: [
"elt.addEventListener('event', handler);" +
"elt.removeEventListener('event', handler);",
--- a/tools/lint/eslint/eslint-plugin-mozilla/tests/no-useless-parameters.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/no-useless-parameters.js
@@ -1,25 +1,25 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Requirements
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
var rule = require("../lib/rules/no-useless-parameters");
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Tests
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
function callError(message) {
- return [{message: message, type: "CallExpression"}];
+ return [{message, type: "CallExpression"}];
}
exports.runTest = function(ruleTester) {
ruleTester.run("no-useless-parameters", rule, {
valid: [
"Services.prefs.clearUserPref('browser.search.custom');",
"Services.removeObserver('notification name', {});",
"Services.io.newURI('http://example.com');",
--- a/tools/lint/eslint/eslint-plugin-mozilla/tests/no-useless-removeEventListener.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/no-useless-removeEventListener.js
@@ -1,27 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Requirements
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
var rule = require("../lib/rules/no-useless-removeEventListener");
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Tests
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
function invalidCode(code) {
let message = "use {once: true} instead of removeEventListener " +
"as the first instruction of the listener";
- return {code: code, errors: [{message: message, type: "CallExpression"}]};
+ return {code, errors: [{message, type: "CallExpression"}]};
}
exports.runTest = function(ruleTester) {
ruleTester.run("no-useless-removeEventListener", rule, {
valid: [
// Listeners that aren't a function are always valid.
"elt.addEventListener('click', handler);",
"elt.addEventListener('click', handler, true);",
--- a/tools/lint/eslint/eslint-plugin-mozilla/tests/test-no-import-into-var-and-global.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/test-no-import-into-var-and-global.js
@@ -1,22 +1,22 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Requirements
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
var rule = require("../lib/rules/no-import-into-var-and-global");
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Tests
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
const ExpectedError = {
message: "Cu.import imports into variables and into global scope.",
type: "CallExpression"
};
exports.runTest = function(ruleTester) {
ruleTester.run("no-import-into-var-and-global", rule, {
--- a/tools/lint/eslint/eslint-plugin-mozilla/tests/test-no-single-arg-cu-import.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/test-no-single-arg-cu-import.js
@@ -1,22 +1,22 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Requirements
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
var rule = require("../lib/rules/no-single-arg-cu-import");
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Tests
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
const ExpectedError = {
message: "Single argument Cu.import exposes new globals to all modules",
type: "CallExpression"
};
exports.runTest = function(ruleTester) {
ruleTester.run("no-single-arg-cu-import", rule, {
--- a/tools/lint/eslint/eslint-plugin-mozilla/tests/test-run-all.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/test-run-all.js
@@ -1,15 +1,15 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const RuleTester = require("eslint/lib/testers/rule-tester");
-const fs = require('fs');
+const fs = require("fs");
var ruleTester = new RuleTester();
fs.readdir(__dirname, (err, files) => {
files.forEach(file => {
if (file != "test-run-all.js" && !file.endsWith("~")) {
console.log(`Running ${file}`);
require("./" + file).runTest(ruleTester);
--- a/tools/lint/eslint/eslint-plugin-mozilla/tests/use-default-preference-values.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/use-default-preference-values.js
@@ -1,26 +1,26 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Requirements
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
var rule = require("../lib/rules/use-default-preference-values");
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Tests
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
function invalidCode(code) {
let message = "provide a default value instead of using a try/catch block";
- return {code: code, errors: [{message: message, type: "TryStatement"}]};
+ return {code, errors: [{message, type: "TryStatement"}]};
}
let types = ["Bool", "Char", "Float", "Int"];
let methods = types.map(type => "get" + type + "Pref");
exports.runTest = function(ruleTester) {
ruleTester.run("use-ownerGlobal", rule, {
valid: [].concat(
--- a/tools/lint/eslint/eslint-plugin-mozilla/tests/use-ownerGlobal.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/use-ownerGlobal.js
@@ -1,26 +1,26 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Requirements
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
var rule = require("../lib/rules/use-ownerGlobal");
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Tests
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
function invalidCode(code) {
let message = "use .ownerGlobal instead of .ownerDocument.defaultView";
- return {code: code, errors: [{message: message, type: "MemberExpression"}]};
+ return {code, errors: [{message, type: "MemberExpression"}]};
}
exports.runTest = function(ruleTester) {
ruleTester.run("use-ownerGlobal", rule, {
valid: [
"aEvent.target.ownerGlobal;",
"this.DOMPointNode.ownerGlobal.getSelection();",
"windowToMessageManager(node.ownerGlobal);"
--- a/tools/lint/eslint/eslint-plugin-spidermonkey-js/lib/index.js
+++ b/tools/lint/eslint/eslint-plugin-spidermonkey-js/lib/index.js
@@ -2,16 +2,16 @@
* @fileoverview A processor to help parse the spidermonkey js code.
* 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";
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
// Plugin Definition
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
module.exports = {
processors: {
".js": require("../lib/processors/self-hosted")
}
};
--- a/tools/lint/eslint/eslint-plugin-spidermonkey-js/lib/processors/self-hosted.js
+++ b/tools/lint/eslint/eslint-plugin-spidermonkey-js/lib/processors/self-hosted.js
@@ -7,17 +7,17 @@
*/
"use strict";
const selfHostedRegex = /js\/src\/(?:builtin|shell)\/.*?\.js$/;
const macroRegex = /\s*\#(if|ifdef|else|elif|endif|include|define|undef).*/;
module.exports = {
- preprocess: function(text, filename) {
+ preprocess(text, filename) {
if (!selfHostedRegex.test(filename)) {
return [text];
}
let lines = text.split(/\n/);
for (let i = 0; i < lines.length; i++) {
if (!macroRegex.test(lines[i])) {
// No macro here, nothing to do.
@@ -33,12 +33,12 @@ module.exports = {
break;
}
}
}
return [lines.join("\n")];
},
- postprocess: function(messages, filename) {
+ postprocess(messages, filename) {
return Array.prototype.concat.apply([], messages);
}
};