Bug 1369722 - Disable ESLint browser environment for jsm files. r?Mossop
MozReview-Commit-ID: IVAyPmTqtCB
--- a/browser/extensions/activity-stream/common/PerfService.jsm
+++ b/browser/extensions/activity-stream/common/PerfService.jsm
@@ -12,16 +12,17 @@ let usablePerfObj;
/* istanbul ignore if */
/* istanbul ignore else */
if (typeof Services !== "undefined") {
// Borrow the high-resolution timer from the hidden window....
usablePerfObj = Services.appShell.hiddenDOMWindow.performance;
} else if (typeof performance !== "undefined") {
// we must be running in content space
+ // eslint-disable-next-line no-undef
usablePerfObj = performance;
} else {
// This is a dummy object so this file doesn't crash in the node prerendering
// task.
usablePerfObj = {
now() {},
mark() {}
};
--- a/toolkit/components/extensions/ExtensionXPCShellUtils.jsm
+++ b/toolkit/components/extensions/ExtensionXPCShellUtils.jsm
@@ -56,17 +56,17 @@ let BASE_MANIFEST = Object.freeze({
});
function frameScript() {
Components.utils.import("resource://gre/modules/Services.jsm");
Services.obs.notifyObservers(this, "tab-content-frameloader-created");
- // eslint-disable-next-line mozilla/balanced-listeners
+ // eslint-disable-next-line mozilla/balanced-listeners, no-undef
addEventListener("MozHeapMinimize", () => {
Services.obs.notifyObservers(null, "memory-pressure", "heap-minimize");
}, true, true);
}
const FRAME_SCRIPT = `data:text/javascript,(${encodeURI(frameScript)}).call(this)`;
let kungFuDeathGrip = new Set();
--- a/toolkit/components/osfile/modules/osfile_shared_allthreads.jsm
+++ b/toolkit/components/osfile/modules/osfile_shared_allthreads.jsm
@@ -121,16 +121,17 @@ exports.defineLazyGetter = defineLazyGet
// /////////////////// Logging
/**
* The default implementation of the logger.
*
* The choice of logger can be overridden with Config.TEST.
*/
var gLogger;
+// eslint-disable-next-line no-undef
if (typeof window != "undefined" && window.console && console.log) {
gLogger = console.log.bind(console, "OS");
} else {
gLogger = function(...args) {
dump("OS " + args.join(" ") + "\n");
};
}
--- a/tools/lint/docs/linters/eslint-plugin-mozilla.rst
+++ b/tools/lint/docs/linters/eslint-plugin-mozilla.rst
@@ -31,16 +31,21 @@ chrome-worker
Defines the environment for chrome workers. This differs from normal workers by
the fact that `ctypes` can be accessed as well.
frame-script
------------
Defines the environment for frame scripts.
+jsm
+---
+
+Defines the environment for jsm files (javascript modules).
+
Rules
=====
avoid-Date-timing
-----------------
Rejects grabbing the current time via Date.now() or new Date() for timing
purposes when the less problematic performance.now() can be used instead.
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
@@ -57,16 +57,23 @@ module.exports = {
"overrides": [{
// Turn off use-services for xml files. XBL bindings are going away, and
// working out the valid globals for those is difficult.
"files": "**/*.xml",
"rules": {
"mozilla/use-services": "off"
}
+ }, {
+ // Turn off browser env for all *.jsm files, and turn on the jsm environment.
+ "env": {
+ "browser": false,
+ "mozilla/jsm": true
+ },
+ "files": "**/*.jsm"
}],
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
},
"ecmaVersion": 8
},
new file mode 100644
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/jsm.js
@@ -0,0 +1,82 @@
+/**
+ * @fileoverview Defines the environment for jsm files.
+ *
+ * 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";
+
+module.exports = {
+ "globals": {
+ // Intl is standard JS availability.
+ "Intl": false,
+ // These globals are hard-coded and available in .jsm scopes.
+ // https://searchfox.org/mozilla-central/rev/ed212c79cfe86357e9a5740082b9364e7f6e526f/js/xpconnect/loader/mozJSComponentLoader.cpp#134-140
+ "atob": false,
+ "btoa": false,
+ "debug": false,
+ "dump": false,
+ // These globals are made available via WebIDL files, see ResolveSystemBinding in:
+ // https://searchfox.org/mozilla-central/source/__GENERATED__/dom/bindings/ResolveSystemBinding.cpp
+ "AbortController": false,
+ "AbortSignal": false,
+ "AddonManagerPermissions": false,
+ "ChannelWrapper": false,
+ "ChromeUtils": false,
+ "ChromeWorker": false,
+ "DOMError": false,
+ "DOMException": false,
+ "DOMRequest": false,
+ "DOMStringList": false,
+ "DominatorTree": false,
+ "ErrorEvent": false,
+ "Event": false,
+ "EventTarget": false,
+ "FileReader": false,
+ "HeapSnapshot": false,
+ "IDBCursor": false,
+ "IDBCursorWithValue": false,
+ "IDBDatabase": false,
+ "IDBFactory": false,
+ "IDBFileHandle": false,
+ "IDBFileRequest": false,
+ "IDBIndex": false,
+ "IDBKeyRange": false,
+ "IDBLocaleAwareKeyRange": false,
+ "IDBMutableFile": false,
+ "IDBObjectStore": false,
+ "IDBOpenDBRequest": false,
+ "IDBRequest": false,
+ "IDBTransaction": false,
+ "IDBVersionChangeEvent": false,
+ "IdleDeadline": false,
+ "MatchGlob": false,
+ "MatchPattern": false,
+ "MatchPatternSet": false,
+ "MessageEvent": false,
+ "MessagePort": false,
+ "PrecompiledScript": false,
+ "PromiseDebugging": false,
+ "StreamFilter": false,
+ "StreamFilterDataEvent": false,
+ "StructuredCloneHolder": false,
+ "TCPServerSocket": false,
+ "TCPServerSocketEvent": false,
+ "TCPSocket": false,
+ "TCPSocketErrorEvent": false,
+ "TCPSocketEvent": false,
+ "TextDecoder": false,
+ "TextEncoder": false,
+ "URLSearchParams": false,
+ "WebExtensionContentScript": false,
+ "WebExtensionPolicy": false,
+ "Worker": false,
+ // Items not defined as System specifically, but available globally.
+ "File": false,
+ "Headers": false,
+ "XMLHttpRequest": false,
+ "URL": false
+ }
+};
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -243,16 +243,33 @@ 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.
*/
convertCallExpressionToGlobals(node, isGlobal) {
+ let express = node.expression;
+ if (express.type === "CallExpression" &&
+ express.callee.type === "MemberExpression" &&
+ express.callee.object &&
+ express.callee.object.type === "Identifier" &&
+ express.arguments.length === 1 &&
+ express.arguments[0].type === "ArrayExpression" &&
+ express.callee.property.type === "Identifier" &&
+ express.callee.property.name === "importGlobalProperties") {
+ return express.arguments[0].elements.map(literal => {
+ return {
+ name: literal.value,
+ writable: false
+ };
+ });
+ }
+
let source;
try {
source = this.getASTSource(node);
} catch (e) {
return [];
}
for (let reg of imports) {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
@@ -18,16 +18,17 @@ module.exports = {
"mochitest-test": require("../lib/configs/mochitest-test"),
"recommended": require("../lib/configs/recommended"),
"xpcshell-test": require("../lib/configs/xpcshell-test")
},
environments: {
"browser-window": require("../lib/environments/browser-window.js"),
"chrome-worker": require("../lib/environments/chrome-worker.js"),
"frame-script": require("../lib/environments/frame-script.js"),
+ "jsm": require("../lib/environments/jsm.js"),
"places-overlay": require("../lib/environments/places-overlay.js"),
"simpletest": require("../lib/environments/simpletest.js")
},
processors: {
".xml": require("../lib/processors/xbl-bindings")
},
rules: {
"avoid-Date-timing": require("../lib/rules/avoid-Date-timing"),
--- a/tools/lint/eslint/eslint-plugin-mozilla/package-lock.json
+++ b/tools/lint/eslint/eslint-plugin-mozilla/package-lock.json
@@ -1,11 +1,11 @@
{
"name": "eslint-plugin-mozilla",
- "version": "0.4.10",
+ "version": "0.5.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"acorn": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-5.2.1.tgz",
"integrity": "sha512-jG0u7c4Ly+3QkkW18V+NRDN+4bWHdln30NL1ZL2AvFZZmQe/BfopYCtghCKKVBUSetZ4QKcyA0pY6/4Gw8Pv8w==",
"dev": true
--- 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.4.10",
+ "version": "0.5.0",
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin",
"mozilla",
"firefox"
],