Bug 1719850 - [marionette] Enforce no-unused-vars for global variables in marionette eslint configuration r=webdriver-reviewers,whimboo

Depends on D119508

Differential Revision: https://phabricator.services.mozilla.com/D119515
This commit is contained in:
Julian Descottes 2021-07-09 17:22:09 +00:00
parent e883000c1c
commit faae156764
31 changed files with 47 additions and 173 deletions

36
remote/.eslintrc.js Normal file
View File

@ -0,0 +1,36 @@
/* 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 = {
rules: {
"no-undef-init": "error",
// This is usually only applied to jsm or jsm.js files.
// But marionette modules are JS files without a jsm extension and use
// the EXPORT_SYMBOLS syntax.
"mozilla/mark-exported-symbols-as-used": "error",
},
overrides: [
{
// The mozilla recommended configuration is not strict enough against
// regular javascript files, compared to JSM. Enforce no-unused-vars on
// "all" variables, not only "local" ones.
files: ["*"],
// test head files and html files typically define global variables
// intended to be used by other files and should not be affected by
// this override.
excludedFiles: ["**/test/**/head.js", "**/test/**/*.html"],
rules: {
"no-unused-vars": [
"error",
{
args: "none",
vars: "all",
},
],
},
},
],
};

View File

@ -492,7 +492,7 @@ class ExecutionContext {
return { type };
}
let unserializableValue = undefined;
let unserializableValue;
if (Object.is(debuggerObj, -0)) {
unserializableValue = "-0";
} else if (Object.is(debuggerObj, NaN)) {

View File

@ -263,8 +263,8 @@ class NetworkObserver {
const causeType = httpChannel.loadInfo
? httpChannel.loadInfo.externalContentPolicyType
: Ci.nsIContentPolicy.TYPE_OTHER;
let remoteIPAddress = undefined;
let remotePort = undefined;
let remoteIPAddress;
let remotePort;
try {
remoteIPAddress = httpChannel.remoteAddress;
remotePort = httpChannel.remotePort;
@ -402,7 +402,7 @@ function readRequestPostData(httpChannel) {
}
// Read data from the stream.
let text = undefined;
let text;
try {
text = NetUtil.readInputStreamToString(iStream, iStream.available());
const converter = Cc[

View File

@ -8,9 +8,7 @@ const SJS_PATH = "/browser/remote/cdp/test/browser/network/sjs-cookies.sjs";
const DEFAULT_HOST = "http://example.org";
const DEFAULT_HOSTNAME = "example.org";
const ALT_HOST = "http://example.net";
const ALT_HOSTNAME = "example.net";
const SECURE_HOST = "https://example.com";
const SECURE_HOSTNAME = "example.com";
const DEFAULT_URL = `${DEFAULT_HOST}${SJS_PATH}`;

View File

@ -9,8 +9,6 @@ const DEFAULT_HOST = "example.org";
const ALT_HOST = "foo.example.org";
const SECURE_HOST = "example.com";
const DEFAULT_URL = `http://${DEFAULT_HOST}`;
add_task(async function failureWithoutArguments({ client }) {
const { Network } = client;

View File

@ -1,2 +1,3 @@
/* eslint-disable no-unused-vars */
// Test file to emit Network events.
var foo = true;

View File

@ -1,2 +1,3 @@
/* eslint-disable no-unused-vars */
// Test file to emit Network events.
var foo = true;

View File

@ -3,10 +3,6 @@
"use strict";
const { SessionStore } = ChromeUtils.import(
"resource:///modules/sessionstore/SessionStore.jsm"
);
add_task(async function singleEntry({ client }) {
const { Page } = client;

View File

@ -3,8 +3,6 @@
"use strict";
/* global getCDP */
// Assert the order of Runtime.executionContextDestroyed,
// Page.frameNavigated, and Runtime.executionContextCreated

View File

@ -3,7 +3,7 @@
"use strict";
const { CDPConnection, splitMethod } = ChromeUtils.import(
const { splitMethod } = ChromeUtils.import(
"chrome://remote/content/cdp/CDPConnection.jsm"
);

View File

@ -3,11 +3,7 @@
"use strict";
const { AsyncShutdown } = ChromeUtils.import(
"resource://gre/modules/AsyncShutdown.jsm"
);
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { StreamRegistry } = ChromeUtils.import(
"chrome://remote/content/cdp/StreamRegistry.jsm"

View File

@ -9,8 +9,6 @@
module.exports = {
rules: {
camelcase: ["error", { properties: "never" }],
"no-fallthrough": "error",
"no-undef-init": "error",
"no-var": "error",
},
};

View File

@ -6,16 +6,12 @@
const EXPORTED_SYMBOLS = ["assert"];
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
AppConstants: "resource://gre/modules/AppConstants.jsm",
AppInfo: "chrome://remote/content/marionette/appinfo.js",
browser: "chrome://remote/content/marionette/browser.js",
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
evaluate: "chrome://remote/content/marionette/evaluate.js",
pprint: "chrome://remote/content/marionette/format.js",

View File

@ -3,30 +3,22 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/* global frame */
const EXPORTED_SYMBOLS = ["browser", "Context", "WindowState"];
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
AppInfo: "chrome://remote/content/marionette/appinfo.js",
element: "chrome://remote/content/marionette/element.js",
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
Log: "chrome://remote/content/shared/Log.jsm",
MessageManagerDestroyedPromise: "chrome://remote/content/marionette/sync.js",
waitForEvent: "chrome://remote/content/marionette/sync.js",
WebElementEventTarget: "chrome://remote/content/marionette/dom.js",
windowManager: "chrome://remote/content/shared/WindowManager.jsm",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.get(Log.TYPES.MARIONETTE)
);
/** @namespace */
this.browser = {};

View File

@ -3,7 +3,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/* global XPCNativeWrapper */
const EXPORTED_SYMBOLS = ["GeckoDriver"];
@ -84,8 +83,6 @@ const SUPPORTED_STRATEGIES = new Set([
// commands if no window manager is present.
const TIMEOUT_NO_WINDOW_MANAGER = 5000;
const globalMessageManager = Services.mm;
/**
* The Marionette WebDriver services provides a standard conforming
* implementation of the W3C WebDriver specification.

View File

@ -3,7 +3,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/* global XPCNativeWrapper */
const EXPORTED_SYMBOLS = [
"ChromeWebElement",

View File

@ -14,7 +14,6 @@ const { XPCOMUtils } = ChromeUtils.import(
XPCOMUtils.defineLazyModuleGetters(this, {
AppInfo: "chrome://remote/content/marionette/appinfo.js",
element: "chrome://remote/content/marionette/element.js",
});
/** Provides functionality for creating and sending DOM events. */

View File

@ -13,8 +13,6 @@ const { XPCOMUtils } = ChromeUtils.import(
);
XPCOMUtils.defineLazyModuleGetters(this, {
Preferences: "resource://gre/modules/Preferences.jsm",
accessibility: "chrome://remote/content/marionette/accessibility.js",
atom: "chrome://remote/content/marionette/atom.js",
element: "chrome://remote/content/marionette/element.js",

View File

@ -15,9 +15,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
OS: "resource://gre/modules/osfile.jsm",
setInterval: "resource://gre/modules/Timer.jsm",
assert: "chrome://remote/content/marionette/assert.js",
Log: "chrome://remote/content/shared/Log.jsm",
pprint: "chrome://remote/content/marionette/format.js",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>

View File

@ -14,12 +14,10 @@ const { XPCOMUtils } = ChromeUtils.import(
XPCOMUtils.defineLazyModuleGetters(this, {
E10SUtils: "resource://gre/modules/E10SUtils.jsm",
OS: "resource://gre/modules/osfile.jsm",
Preferences: "resource://gre/modules/Preferences.jsm",
AppInfo: "chrome://remote/content/marionette/appinfo.js",
assert: "chrome://remote/content/marionette/assert.js",
capture: "chrome://remote/content/marionette/capture.js",
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
Log: "chrome://remote/content/shared/Log.jsm",
navigate: "chrome://remote/content/marionette/navigate.js",
print: "chrome://remote/content/marionette/print.js",

View File

@ -6,14 +6,11 @@
const EXPORTED_SYMBOLS = ["TCPConnection", "TCPListener"];
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
OS: "resource://gre/modules/osfile.jsm",
assert: "chrome://remote/content/marionette/assert.js",
Command: "chrome://remote/content/marionette/message.js",
DebuggerTransport: "chrome://remote/content/marionette/transport.js",

View File

@ -30,7 +30,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
EventDispatcher:
"chrome://remote/content/marionette/actors/MarionetteEventsParent.jsm",
Log: "chrome://remote/content/shared/Log.jsm",
truncate: "chrome://remote/content/marionette/format.js",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>

View File

@ -11,11 +11,7 @@ const {
} = ChromeUtils.import(
"chrome://remote/content/marionette/actors/MarionetteCommandsParent.jsm"
);
const {
EventDispatcher,
registerEventsActor,
unregisterEventsActor,
} = ChromeUtils.import(
const { registerEventsActor, unregisterEventsActor } = ChromeUtils.import(
"chrome://remote/content/marionette/actors/MarionetteEventsParent.jsm"
);

View File

@ -10,9 +10,6 @@ const {
element,
WebElement,
} = ChromeUtils.import("chrome://remote/content/marionette/element.js");
const { InvalidArgumentError } = ChromeUtils.import(
"chrome://remote/content/shared/webdriver/Errors.jsm"
);
const SVG_NS = "http://www.w3.org/2000/svg";
const XHTML_NS = "http://www.w3.org/1999/xhtml";

View File

@ -1,4 +1,4 @@
const { element, ReferenceStore, WebElement } = ChromeUtils.import(
const { element, WebElement } = ChromeUtils.import(
"chrome://remote/content/marionette/element.js"
);
const { evaluate } = ChromeUtils.import(

View File

@ -1,4 +1,4 @@
const { element, ReferenceStore, WebElement } = ChromeUtils.import(
const { element, WebElement } = ChromeUtils.import(
"chrome://remote/content/marionette/element.js"
);

View File

@ -20,10 +20,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
StreamUtils: "chrome://remote/content/marionette/stream-utils.js",
});
XPCOMUtils.defineLazyGetter(this, "Pipe", () => {
return Components.Constructor("@mozilla.org/pipe;1", "nsIPipe", "init");
});
XPCOMUtils.defineLazyGetter(this, "ScriptableInputStream", () => {
return Components.Constructor(
"@mozilla.org/scriptableinputstream;1",

View File

@ -3,8 +3,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Log } = ChromeUtils.import("chrome://remote/content/shared/Log.jsm");
const logger = Log.get();
const COMMON_PREF = "toolkit.startup.max_resumed_crashes";

View File

@ -2,107 +2,10 @@
* 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/. */
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { AnimationFramePromise, PollPromise } = ChromeUtils.import(
"chrome://remote/content/shared/Sync.jsm"
);
/**
* Mimic a DOM node for listening for events.
*/
class MockElement {
constructor() {
this.capture = false;
this.func = null;
this.eventName = null;
this.untrusted = false;
}
addEventListener(name, func, capture, untrusted) {
this.eventName = name;
this.func = func;
if (capture != null) {
this.capture = capture;
}
if (untrusted != null) {
this.untrusted = untrusted;
}
}
click() {
if (this.func) {
let details = {
capture: this.capture,
target: this,
type: this.eventName,
untrusted: this.untrusted,
};
this.func(details);
}
}
removeEventListener(name, func) {
this.capture = false;
this.func = null;
this.eventName = null;
this.untrusted = false;
}
}
/**
* Mimic a message manager for sending messages.
*/
class MessageManager {
constructor() {
this.func = null;
this.message = null;
}
addMessageListener(message, func) {
this.func = func;
this.message = message;
}
removeMessageListener(message) {
this.func = null;
this.message = null;
}
send(message, data) {
if (this.func) {
this.func({
data,
message,
target: this,
});
}
}
}
/**
* Mimics nsITimer, but instead of using a system clock you can
* preprogram it to invoke the callback after a given number of ticks.
*/
class MockTimer {
constructor(ticksBeforeFiring) {
this.goal = ticksBeforeFiring;
this.ticks = 0;
this.cancelled = false;
}
initWithCallback(cb, timeout, type) {
this.ticks++;
if (this.ticks >= this.goal) {
cb();
}
}
cancel() {
this.cancelled = true;
}
}
add_task(async function test_AnimationFramePromise() {
let called = false;
let win = {

View File

@ -4,20 +4,9 @@
"use strict";
const { Preferences } = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { AppInfo } = ChromeUtils.import(
"chrome://remote/content/marionette/appinfo.js"
);
const { Capabilities, Timeouts } = ChromeUtils.import(
"chrome://remote/content/shared/webdriver/Capabilities.jsm"
);
const { error } = ChromeUtils.import(
"chrome://remote/content/shared/webdriver/Errors.jsm"
);
const { WebDriverSession } = ChromeUtils.import(
"chrome://remote/content/shared/webdriver/Session.jsm"
);

View File

@ -129,7 +129,7 @@ class WebDriverBiDiConnection extends WebSocketConnection {
throw new TypeError("Message missing 'method' field");
}
let result = undefined;
let result;
this.sendResult(id, result);
} catch (e) {