Browse Source

Review and fix most linting issues.

1.1.101
Jorg Knobloch 2 years ago
parent
commit
a49aed0d5e
11 changed files with 43 additions and 69 deletions
  1. +13
    -32
      .eslintrc.json
  2. +5
    -1
      chrome/bootstrap.js
  3. +2
    -4
      chrome/content/TbHelper.js
  4. +1
    -2
      chrome/content/detectAdapter.js
  5. +2
    -0
      chrome/content/modules/pEp.js
  6. +3
    -20
      chrome/content/modules/pEpAdapter.js
  7. +3
    -0
      chrome/content/modules/xhrQueue.js
  8. +2
    -2
      chrome/content/options.js
  9. +1
    -0
      chrome/content/pEpForThunderbird.js
  10. +8
    -6
      chrome/content/pepmessengercompose.js
  11. +3
    -2
      chrome/content/pepmsghdrview.js

+ 13
- 32
.eslintrc.json View File

@ -36,51 +36,32 @@
"warn", "double"
],
"comment will leave the following": "off",
"array-callback-return": "off",
"camelcase": "off",
"class-methods-use-this": "off",
"guard-for-in": "off",
"max-classes-per-file": "off",
"new-cap": "off",
"no-bitwise": "off",
"no-console": "off",
"no-plusplus": "off",
"no-prototype-builtins": "off",
"no-underscore-dangle": "off",
"comment will need to look at all the following one-by-one": "off",
"array-callback-return": "off",
"block-scoped-var": "off",
"class-methods-use-this": "off",
"default-case": "off",
"eqeqeq": "off",
"func-names": "off",
"function-paren-newline": "off",
"global-require": "off",
"guard-for-in": "off",
"implicit-arrow-linebreak": "off",
"indent": "off",
"max-len": "off",
"no-empty": "off",
"no-empty-function": "off",
"no-fallthrough": "off",
"no-inner-declarations": "off",
"no-multi-spaces": "off",
"no-param-reassign": "off",
"no-plusplus": "off",
"no-prototype-builtins": "off",
"no-restricted-syntax": "off",
"no-shadow": "off",
"no-unreachable": "off",
"no-underscore-dangle": "off",
"no-unused-expressions": "off",
"no-unused-vars": "off",
"no-use-before-define": "off",
"no-var": "off",
"nonblock-statement-body-position": "off",
"object-curly-spacing": "off",
"object-shorthand": "off",
"operator-linebreak": "off",
"prefer-const": "off",
"prefer-destructuring": "off",
"prefer-promise-reject-errors": "off",
"prefer-rest-params": "off",
"prefer-template": "off",
"space-unary-ops": "off",
"vars-on-top": "off"
"comment will need to look at all the following one-by-one": "off",
"eqeqeq": "off",
"indent": "off",
"max-len": "off",
"no-unused-vars": "off",
"object-curly-spacing": "off"
}
}

+ 5
- 1
chrome/bootstrap.js View File

@ -28,8 +28,10 @@ function setPrefs(prefBranch) {
// String: {
// },
};
iterate(["Bool", "String"], defaults);
// iterate(["Bool", "String"], defaults);
iterate(["Bool"], defaults);
// eslint-disable-next-line no-shadow
function iterate(types, defaults) {
types.map((type) => {
const prefs = defaults[type];
@ -106,5 +108,7 @@ function unpaint(win) {
case "chrome://messenger/content/messengercompose/messengercompose.xul":
win.pEpComposer.destroy();
break;
default:
}
}

+ 2
- 4
chrome/content/TbHelper.js View File

@ -39,8 +39,7 @@ const TbHelper = {
msgWindow, // a nsIMsgWindow for progress and status feedback
null, // a nsIUrlListener that is notified when url starts and stops
false, // it will create a stream converter from message rfc2822 to
null, // Header added to the URI. e.g., header=filter
);
null); // Header added to the URI. e.g., header=filter
} catch (ex) {
console.debug("Error while reading mail from server", ex);
}
@ -129,8 +128,7 @@ const TbHelper = {
const msgCopyService = Cc["@mozilla.org/messenger/messagecopyservice;1"]
.getService(Ci.nsIMsgCopyService);
msgCopyService.CopyFileMessage(
tempFile, msgFolder, msgHdr, false, 0, "", copyListener, null);
msgCopyService.CopyFileMessage(tempFile, msgFolder, msgHdr, false, 0, "", copyListener, null);
},
isOwnIdentity(email) {


+ 1
- 2
chrome/content/detectAdapter.js View File

@ -11,12 +11,11 @@ var {pEpLogger} = ChromeUtils.import("resource://pEp4Tb/content/pEpLogger.js");
*
* @return String - URL to connect with pEp JSON Server
*/
const detectAdapter = function () {
const detectAdapter = () => {
const logger = new pEpLogger(LEVEL_ALL);
logger.info("detectJsonAdapter()");
const env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
const files = new pEpFiles();
const os = new pEpOs();


+ 2
- 0
chrome/content/modules/pEp.js View File

@ -26,7 +26,9 @@ const ENC_FORMAT_PEP = 4;
const PEP_PREFIX = "pEp-";
// Added for the tests where btoa is not defined
// eslint-disable-next-line block-scoped-var
if (typeof btoa === "undefined" && typeof require === "function") {
// eslint-disable-next-line global-require, vars-on-top
var btoa = require("btoa");
}


+ 3
- 20
chrome/content/modules/pEpAdapter.js View File

@ -29,10 +29,7 @@ const ENC_FORMAT_PGP_MIME = 3;
const ENC_FORMAT_PEP = 4;
const PEP_PREFIX = "pEp-";
const JRPC_INTERNAL_ERROR = -32603;
const PEP_RESPONSE_OK = 0;
const PEP_ILLEGAL_VALUE = -4;
const PEP_UNENCRYPTED = 1024;
const PEP_RESPONSE_DECRYPTED = 1026;
const PEP_KEY_NOT_FOUND = 0x0201;
@ -134,9 +131,8 @@ class pEpAdapter {
SERVER_TYPE_CALL_FUNC,
API_METHOD_GET_TRUSTWORDS,
params,
).then((response) =>
).then((response) => response.result.outParams[1]).catch((err) => {
// TODO Validate length (outParams[0]) with words (outParams[1])
response.result.outParams[1]).catch((err) => {
this.log.error(err.message, err);
return err;
});
@ -258,11 +254,7 @@ class pEpAdapter {
console.log("pEpAdapter.js: decrypt() success: ", response);
if ((typeof (response) === "object") && response.hasOwnProperty("error")) {
switch (response.error.code) {
case -32603:
throw new Error({code: "PEP-ERROR", message: response.error.message, response});
break;
}
throw new Error({code: "PEP-ERROR", message: response.error.message, response});
}
if (!(typeof response === "object"
@ -329,11 +321,7 @@ class pEpAdapter {
let encryptedMessage = {};
if ((typeof (response) === "object") && response.hasOwnProperty("error")) {
switch (response.error.code) {
case JRPC_INTERNAL_ERROR:
throw new Error({code: "PEP-ERROR", message: response.error.message, response});
break;
}
throw new Error({code: "PEP-ERROR", message: response.error.message, response});
}
if (!(typeof response === "object"
@ -358,11 +346,6 @@ class pEpAdapter {
this.log.debug("callPepAdapter: 'encrypt' returned with UNENCRYPTED status: ", response);
break;
case (PEP_ILLEGAL_VALUE):
encryptedMessage = response.result.outParams[1];
encryptedMessage.enc_format = ENC_FORMAT_NONE; // We couldn't encrypt, so this is unencrypted.
this.log.debug("callPepAdapter: 'encrypt' returned with illegal value", response.result.return, message);
default:
this.log.debug("callPepAdapter: 'encrypt' returned with error: ", response);
throw new Error({code: response.result.return.status, message: response});


+ 3
- 0
chrome/content/modules/xhrQueue.js View File

@ -7,6 +7,7 @@ class XhrQueue {
this.XMLHttpRequest = XMLHttpRequest;
if (typeof XMLHttpRequest === "undefined") {
// eslint-disable-next-line global-require
this.XMLHttpRequest = require("xhr2");
}
}
@ -29,6 +30,7 @@ class XhrQueue {
if (xhr.status >= 200 && xhr.status < 300) {
resolve(JSON.parse(xhr.response));
} else {
// eslint-disable-next-line prefer-promise-reject-errors
reject({
status: xhr.status,
statusText: xhr.statusText,
@ -37,6 +39,7 @@ class XhrQueue {
};
xhr.onerror = () => {
// eslint-disable-next-line prefer-promise-reject-errors
reject({
status: xhr.status || 500,
statusText: xhr.statusText || "pEp engine not available",


+ 2
- 2
chrome/content/options.js View File

@ -71,7 +71,7 @@ function loadAccounts() {
let id = `mail.identity.${identity.key}.enableEncryption`;
// Get prior value, if any. Default to true.
let value = Services.prefs.getBoolPref(id, true);
Preferences.add({id: id, type: "bool"});
Preferences.add({id, type: "bool"});
checkbox.setAttribute("preference", id);
Services.prefs.setBoolPref(id, value);
@ -95,7 +95,7 @@ function loadAccounts() {
let id = `mail.account.${account.key}.storeSecurely`;
// Get prior value, if any. Default to true.
let value = storeAllSecurely ? true : Services.prefs.getBoolPref(id, true);
Preferences.add({id: id, type: "bool"});
Preferences.add({id, type: "bool"});
checkbox.setAttribute("preference", id);
Services.prefs.setBoolPref(id, value);
checkbox.setAttribute("disabled", storeAllSecurely);


+ 1
- 0
chrome/content/pEpForThunderbird.js View File

@ -16,6 +16,7 @@ var {
class pEpForThunderbird extends pEp {
constructor(env, logger, adapter, files, os) {
// eslint-disable-next-line prefer-rest-params
super(...arguments);
this.factories = {};
this.hdrViewCount = 0;


+ 8
- 6
chrome/content/pepmessengercompose.js View File

@ -67,7 +67,8 @@ function isPrivate(rating) {
return rating && rating > 5;
}
// Needs to be a `var` since it's used in bootstrap.js.
// eslint-disable-next-line vars-on-top
var pEpComposer = {
init(window) {
@ -118,7 +119,7 @@ var pEpComposer = {
this.originalRatingPromise
.then((originalRating) => {
this.originalRating = originalRating;
console.log("updateRating: original rating: " + originalRating);
console.log(`updateRating: original rating: ${originalRating}`);
if (this.firstUpdate) {
// We are here for the first time, so let's see whether we should encrypt.
// We always encrypt if the original was private, see P4TB-75.
@ -148,7 +149,7 @@ var pEpComposer = {
return Promise.resolve(0);
})
.then((rating) => {
console.log("updateRating: current rating: " + rating);
console.log(`updateRating: original rating: ${rating}`);
this.rating = rating;
createPrivacyNode(rating, this.protectionDisabled);
})
@ -192,7 +193,7 @@ var pEpComposer = {
// and moving a pill to a different recipient type also runs the callback.
// Monkey patching onAddressColCommand event to add some pEp functionality.
if (typeof(onAddressColCommand) == "function") { // Only exists in TB 68.
if (typeof onAddressColCommand == "function") { // Only exists in TB 68.
const tb_onAddressColCommand = onAddressColCommand;
// eslint-disable-next-line no-global-assign
onAddressColCommand = (aAddressWidgetId) => {
@ -264,6 +265,7 @@ var pEpComposer = {
compSec = compSec.wrappedJSObject;
// No such function yet, maybe introduced later.
// compSec.init(/* some init value */);
// eslint-disable-next-line operator-linebreak
[compSec.fromSender, compSec.toRecipients, compSec.ccRecipients, compSec.bccRecipients, compSec.replyToRecipients] =
this.getAddresses(TbAbstraction.getCurrentIdentity(), getCompFields());
compSec.originalSubject = compFields.subject;
@ -273,8 +275,8 @@ var pEpComposer = {
// This is a hack. We tell the engine whether we want protected subjects,
// but when we pass the MIME tree back in pEpMimeEncrypt.js, the engine-provided
// headers are just ignored. So we manipulate the header here manually which isn't ideal.
if (isPrivate(this.rating) &&
Services.prefs.getBoolPref("extensions.pEp.protectSubjects", true)) {
if (isPrivate(this.rating)
&& Services.prefs.getBoolPref("extensions.pEp.protectSubjects", true)) {
compFields.subject = PEP_ENCRYPTED_SUBJECT;
}
}


+ 3
- 2
chrome/content/pepmsghdrview.js View File

@ -261,6 +261,7 @@ var pEpHdrView = {
if (messagePanelFrame != null) {
pEpController.log.debug("pepmsghdrview.js: onLoadListener() added listener");
// eslint-disable-next-line no-inner-declarations
function updateMessagePanel() {
decryptedPromise.then((decryptedMessage) => {
// Validations
@ -301,8 +302,8 @@ function storeDecryptedCopy(msgHdr, mimeMessage) {
// Find the account for this message and check its preference.
let msgRoot = msgHdr.folder.server.rootFolder;
for (let account of fixIterator(MailServices.accounts.accounts, Ci.nsIMsgAccount)) {
if (msgRoot == account.incomingServer.rootMsgFolder &&
!Services.prefs.getBoolPref(`mail.account.${account.key}.storeSecurely`, true)) {
if (msgRoot == account.incomingServer.rootMsgFolder
&& !Services.prefs.getBoolPref(`mail.account.${account.key}.storeSecurely`, true)) {
TbHelper.copyMessageToFolder(msgHdr, mimeMessage);
break;
}


Loading…
Cancel
Save