Skip to content

Commit

Permalink
use eslint-plugin-mozilla
Browse files Browse the repository at this point in the history
  • Loading branch information
lieser committed Jul 25, 2021
1 parent d25f1cf commit d5b742b
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 55 deletions.
15 changes: 13 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"root": true,
"plugins": [
"jsdoc",
"mocha"
"mocha",
"mozilla"
],
"extends": [
"eslint:recommended",
Expand Down Expand Up @@ -156,7 +157,17 @@
],
"jsdoc/require-returns-description": "off",
// Mocha
"mocha/no-return-from-async": "warn"
"mocha/no-return-from-async": "warn",
// Mozilla
"mozilla/avoid-removeChild": "warn",
"mozilla/consistent-if-bracing": "warn",
"mozilla/no-compare-against-boolean-literals": "warn",
"mozilla/no-useless-removeEventListener": "warn",
"mozilla/prefer-boolean-length-check": "warn",
"mozilla/prefer-formatValues": "warn",
"mozilla/use-includes-instead-of-indexOf": "warn",
"mozilla/use-ownerGlobal": "warn",
"mozilla/use-returnValue": "warn"
},
"reportUnusedDisableDirectives": true
}
28 changes: 28 additions & 0 deletions experiments/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
{
"plugins": [
"mozilla"
],
"env": {
"mozilla/privileged": true
},
"parserOptions": {
"sourceType": "script"
},
"globals": {
"Cc": false,
"Ci": false,
"Cr": false,
"Cu": false
},
"rules": {
"mozilla/no-define-cc-etc": "warn",
"mozilla/no-throw-cr-literal": "warn",
"mozilla/no-useless-parameters": "warn",
"mozilla/reject-chromeutils-import-params": "warn",
"mozilla/reject-importGlobalProperties": [
"warn",
"allownonwebidl"
],
"mozilla/rejects-requires-await": "warn",
"mozilla/use-cc-etc": "warn",
"mozilla/use-chromeutils-generateqi": "warn",
"mozilla/use-chromeutils-import": "warn",
"mozilla/use-default-preference-values": "warn",
"mozilla/use-services": "warn"
}
}
43 changes: 20 additions & 23 deletions experiments/JSDNS.jsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,14 @@

//@ts-check
// options for ESLint
/* eslint-env worker */
/* eslint-disable prefer-template */
/* eslint-disable no-use-before-define */
/* eslint-disable camelcase */
/* eslint-disable no-var */
/* eslint strict: ["warn", "function"] */
/* eslint complexity: "off" */
/* eslint no-magic-numbers: "off" */
/* global Components */
/* exported EXPORTED_SYMBOLS, JSDNS */
/* eslint mozilla/mark-exported-symbols-as-used: "error" */


var EXPORTED_SYMBOLS = [
Expand Down Expand Up @@ -312,7 +310,7 @@ function getOsDnsServers() {
/** @type {DnsServer[]} */
const OS_DNS_ROOT_NAME_SERVERS = [];

if ("@mozilla.org/windows-registry-key;1" in Components.classes) {
if ("@mozilla.org/windows-registry-key;1" in Cc) {
// Firefox 1.5 or newer on Windows
// Try getting a nameserver from the windows registry
var reg;
Expand All @@ -321,9 +319,9 @@ function getOsDnsServers() {
var registryLinkage;
var registryInterfaces;
try {
var registry_class = Components.classes["@mozilla.org/windows-registry-key;1"];
var registry_class = Cc["@mozilla.org/windows-registry-key;1"];
var registry_object = registry_class.createInstance();
registry = registry_object.QueryInterface(Components.interfaces.nsIWindowsRegKey);
registry = registry_object.QueryInterface(Ci.nsIWindowsRegKey);

registry.open(registry.ROOT_KEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet",
Expand Down Expand Up @@ -431,14 +429,14 @@ function getOsDnsServers() {
/** @type {nsIFileInputStream} */
var stream_filestream;
try {
var resolvconf = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIFile);
var resolvconf = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
resolvconf.initWithPath("/etc/resolv.conf");

var stream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance();
stream_filestream = stream.QueryInterface(Components.interfaces.nsIFileInputStream);
var stream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance();
stream_filestream = stream.QueryInterface(Ci.nsIFileInputStream);
stream_filestream.init(resolvconf, 0, 0, 0); // don't know what the flags are...

var stream_reader = stream.QueryInterface(Components.interfaces.nsILineInputStream);
var stream_reader = stream.QueryInterface(Ci.nsILineInputStream);

var out_line = { value: "" };
var hasmore = false;
Expand Down Expand Up @@ -610,7 +608,7 @@ function queryDNSRecursive(server, host, recordtype, callback, callbackdata, hop
if (servers === undefined) {
callback(null, callbackdata, ["TIMED_OUT", server]);
}
} else if (status === Components.results.NS_ERROR_NET_TIMEOUT) {
} else if (status === Cr.NS_ERROR_NET_TIMEOUT) {
log.debug("Resolving " + host + "/" + recordtype + ": DNS server " + server + " timed out on a TCP connection (NS_ERROR_NET_TIMEOUT).");
if (servers === undefined) {
callback(null, callbackdata, ["TIMED_OUT", server]);
Expand Down Expand Up @@ -650,7 +648,7 @@ function queryDNSRecursive(server, host, recordtype, callback, callbackdata, hop

this.readcount += data.length;

while (this.responseHeader.length < 14 && data.length > 0) {
while (this.responseHeader.length < 14 && data.length) {
this.responseHeader += data.charAt(0);
data = data.substr(1);
}
Expand All @@ -674,7 +672,7 @@ function queryDNSRecursive(server, host, recordtype, callback, callbackdata, hop
// allow server to be either a hostname or hostname:port
var server_hostname = server;
var port = 53;
if (server.indexOf(':') !== -1) {
if (server.includes(':')) {
server_hostname = server.substring(0, server.indexOf(':'));
port = parseInt(server.substring(server.indexOf(':') + 1), 10);
}
Expand Down Expand Up @@ -889,7 +887,7 @@ function DNS_getRDData(str, server, host, recordtype, callback, callbackdata, ho
}
}

if (results.length > 0) {
if (results.length) {
// We have an answer.
callback(results, callbackdata);

Expand Down Expand Up @@ -969,8 +967,8 @@ function DNS_readAllFromSocket(host, port, outputData, listener) {
try {
var proxy = null;
if (PROXY_CONFIG.enable) {
var pps = Components.classes["@mozilla.org/network/protocol-proxy-service;1"].
getService(Components.interfaces.nsIProtocolProxyService);
var pps = Cc["@mozilla.org/network/protocol-proxy-service;1"].
getService(Ci.nsIProtocolProxyService);
proxy = pps.newProxyInfo(
PROXY_CONFIG.type,
PROXY_CONFIG.host,
Expand All @@ -980,8 +978,8 @@ function DNS_readAllFromSocket(host, port, outputData, listener) {
}

var transportService =
Components.classes["@mozilla.org/network/socket-transport-service;1"].
getService(Components.interfaces.nsISocketTransportService);
Cc["@mozilla.org/network/socket-transport-service;1"].
getService(Ci.nsISocketTransportService);
const transport = transportService.createTransport([], host, port, proxy, null);

// change timeout for connection
Expand All @@ -994,8 +992,8 @@ function DNS_readAllFromSocket(host, port, outputData, listener) {
outstream.write(outputData, outputData.length);

var stream = transport.openInputStream(0, 0, 0);
var instream = Components.classes["@mozilla.org/binaryinputstream;1"].
createInstance(Components.interfaces.nsIBinaryInputStream);
var instream = Cc["@mozilla.org/binaryinputstream;1"].
createInstance(Ci.nsIBinaryInputStream);
instream.setInputStream(stream);

/** @type {nsIStreamListener & {data: string}} */
Expand Down Expand Up @@ -1026,9 +1024,8 @@ function DNS_readAllFromSocket(host, port, outputData, listener) {
}
};

var pump = Components.
classes["@mozilla.org/network/input-stream-pump;1"].
createInstance(Components.interfaces.nsIInputStreamPump);
var pump = Cc["@mozilla.org/network/input-stream-pump;1"].
createInstance(Ci.nsIInputStreamPump);
pump.init(stream, 0, 0, false);
pump.asyncRead(dataListener, null);
} catch (ex) {
Expand Down
11 changes: 5 additions & 6 deletions experiments/dkimHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
///<reference path="./dkimHeader.d.ts" />
///<reference path="./mozilla.d.ts" />
///<reference path="./mozillaDom.d.ts" />
/* eslint-env worker */
/* global ChromeUtils, Components, ExtensionCommon */
/* global ExtensionCommon */

"use strict";

Expand Down Expand Up @@ -58,14 +57,14 @@ class DKIMTooltip {
set warnings(warnings) {
// delete old warnings from tooltips
while (this.element._warningsBox.firstChild) {
this.element._warningsBox.removeChild(this.element._warningsBox.firstChild);
this.element._warningsBox.firstChild.remove();
}

if (!this.element.ownerDocument) {
throw Error("Underlying element of DKIMTooltip does not contain ownerDocument");
}

if (this._warningsSeparator && warnings.length > 0) {
if (this._warningsSeparator && warnings.length) {
const sep = this.element.ownerDocument.createXULElement("separator");
sep.setAttribute("class", "thin");
this.element._warningsBox.appendChild(sep);
Expand Down Expand Up @@ -265,7 +264,7 @@ class DKIMHeaderField {
* @memberof DKIMHeaderField
*/
set warnings(warnings) {
if (warnings.length > 0) {
if (warnings.length) {
this.element._dkimWarningIcon.style.display = "";
} else {
this.element._dkimWarningIcon.style.display = "none";
Expand Down Expand Up @@ -858,7 +857,7 @@ this.dkimHeader = class extends ExtensionCommon.ExtensionAPI {
*/
getDocumentForCurrentMsg(tabId, messageId) {
const target = ExtensionParent.apiManager.global.tabTracker.getTab(tabId);
const window = Components.utils.getGlobalForObject(target);
const window = Cu.getGlobalForObject(target);
const msg = this.extension.messageManager.convert(
window.gFolderDisplay.selectedMessage);
if (msg.id !== messageId) {
Expand Down
5 changes: 2 additions & 3 deletions experiments/jsdns.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
// @ts-check
///<reference path="./jsdns.d.ts" />
///<reference path="./mozilla.d.ts" />
/* eslint-env worker */
/* global ChromeUtils, Components, ExtensionCommon */
/* global ExtensionCommon */

"use strict";

Expand Down Expand Up @@ -112,7 +111,7 @@ this.jsdns = class extends ExtensionCommon.ExtensionAPI {
}

close() {
Components.utils.unload(this.extension.rootURI.resolve("experiments/JSDNS.jsm.js"));
Cu.unload(this.extension.rootURI.resolve("experiments/JSDNS.jsm.js"));
Services.obs.notifyObservers(null, "startupcache-invalidate");
}
};
7 changes: 3 additions & 4 deletions experiments/libunbound.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
// @ts-check
///<reference path="./libunbound.d.ts" />
///<reference path="./mozilla.d.ts" />
/* eslint-env worker */
/* global ChromeUtils, ChromeWorker, Components, ExtensionCommon */
/* global ExtensionCommon */

"use strict";

Expand Down Expand Up @@ -348,9 +347,9 @@ this.libunbound = class extends ExtensionCommon.ExtensionAPI {
constructor(extension) {
super(extension);

const aomStartup = Components.classes[
const aomStartup = Cc[
"@mozilla.org/addons/addon-manager-startup;1"
].getService(Components.interfaces.amIAddonManagerStartup);
].getService(Ci.amIAddonManagerStartup);
const manifestURI = Services.io.newURI(
"manifest.json",
null,
Expand Down
3 changes: 1 addition & 2 deletions experiments/libunboundWorker.jsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
// @ts-check
///<reference path="./ctypes.d.ts" />
///<reference path="./libunbound.d.ts" />
/* eslint-env mozilla/chrome-worker, mozilla/jsm */
/* eslint-disable camelcase */
/* eslint no-global-assign: ["error", {"exceptions": ["onmessage"]}] */
/* global ctypes, onmessage, postMessage, dump */
/* exported onmessage */

"use strict";

Expand Down
7 changes: 3 additions & 4 deletions experiments/mailUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
// @ts-check
///<reference path="./mailUtils.d.ts" />
///<reference path="./mozilla.d.ts" />
/* eslint-env worker */
/* global ChromeUtils, Components, ExtensionCommon */
/* global ExtensionCommon */

"use strict";

Expand All @@ -38,14 +37,14 @@ this.mailUtils = class extends ExtensionCommon.ExtensionAPI {
// eslint-disable-next-line require-await
getBaseDomainFromAddr: async (addr) => {
// var fullDomain = addr.substr(addr.lastIndexOf("@")+1);
const nsiURI = Services.io.newURI(`http://${addr}`, null, null);
const nsiURI = Services.io.newURI(`http://${addr}`);
try {
return Services.eTLD.getBaseDomain(nsiURI);
} catch (e) {
// domains like "blogspot.co.uk", "blogspot.com", "googlecode.com"
// are on the public suffix list, but should be valid base domains
// because e-mails may be send from them
if (e.result === Components.results.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
if (e.result === Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
// add "invalid" subdomain to avoid error
const invalidSub = "invalid.";
const host = invalidSub + nsiURI.asciiHost;
Expand Down
5 changes: 2 additions & 3 deletions experiments/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
// @ts-check
///<reference path="./migration.d.ts" />
///<reference path="./mozilla.d.ts" />
/* eslint-env worker */
/* global ChromeUtils, ExtensionCommon */
/* global ExtensionCommon */

"use strict";

Expand Down Expand Up @@ -99,7 +98,7 @@ this.migration = class extends ExtensionCommon.ExtensionAPI {
const server = mailPrefs.getCharPref(`account.${account}.server`);
const dkimAccountPrefs = Services.prefs.getBranch(`mail.server.${server}.dkim_verifier.`);
const prefs = this._getChildPrefs(dkimAccountPrefs);
if (Object.keys(prefs).length > 0) {
if (Object.keys(prefs).length) {
accountPrefs[account] = prefs;
}
}
Expand Down
6 changes: 5 additions & 1 deletion experiments/mozilla.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ declare module Components {
unload(url: string): void;
}
}
declare const Cc: typeof Components.classes;
declare const Ci: typeof Components.interfaces;
declare const Cr: typeof Components.results;
declare const Cu: typeof Components.utils;

/**
* The `console` global in Chrome context allows creating ConsoleInstance
Expand Down Expand Up @@ -269,7 +273,7 @@ interface nsIProxyInfo { nsIProxyInfo: never };
type nsIObserver = object;

interface nsIIOService {
newURI(aSpec: string, aOriginCharset: string | null, aBaseURI: nsIURI | null): nsIURI;
newURI(aSpec: string, aOriginCharset?: string | null, aBaseURI?: nsIURI | null): nsIURI;
}

interface nsIURI {
Expand Down
1 change: 0 additions & 1 deletion experiments/storageMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
// @ts-check
///<reference path="./storageMessage.d.ts" />
///<reference path="./mozilla.d.ts" />
/* eslint-env worker */
/* global ExtensionCommon */

"use strict";
Expand Down
2 changes: 1 addition & 1 deletion modules/authVerifier.mjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async function getARHResult(message, headers, from, listId, account, dmarc) {
const allowedAuthserv = prefs["account.arh.allowedAuthserv"](account).
split(" ").
filter(server => server);
if (allowedAuthserv.length > 0 &&
if (allowedAuthserv.length &&
!allowedAuthserv.some(server => {
if (arh.authserv_id === server) {
return true;
Expand Down
Loading

0 comments on commit d5b742b

Please sign in to comment.