Selectively run ESLint on js/background.js

Enabling ESLint on a per function basis allows us to incrementally improve the codebase
without requiring large and potentially risky refactorings.
This commit is contained in:
Daniel Gasienica
2018-02-13 09:54:04 -05:00
parent e6d1cf826b
commit a48ba1c774
2 changed files with 61 additions and 40 deletions

View File

@@ -15,5 +15,6 @@ test/views/*.js
/*.js /*.js
# ES2015+ files # ES2015+ files
!js/background.js
!main.js !main.js
!prepare_build.js !prepare_build.js

View File

@@ -1,3 +1,17 @@
/* eslint-disable */
/* eslint-env browser */
/* global Backbone: false */
/* global $: false */
/* global ConversationController: false */
/* global getAccountManager: false */
/* global storage: false */
/* global textsecure: false */
/* global Whisper: false */
/* global wrapDeferred: false */
/* /*
* vim: ts=4:sw=4:expandtab * vim: ts=4:sw=4:expandtab
*/ */
@@ -482,49 +496,55 @@
}); });
} }
async function onMessageReceived(ev) { /* eslint-enable */
const { data } = ev; /* jshint ignore:start */
async function onMessageReceived(ev) {
const { data } = ev;
if (data.message.flags & textsecure.protobuf.DataMessage.Flags.PROFILE_KEY_UPDATE) { // eslint-disable-next-line no-bitwise
const profileKey = data.message.profileKey.toArrayBuffer(); if (data.message.flags & textsecure.protobuf.DataMessage.Flags.PROFILE_KEY_UPDATE) {
const sender = ConversationController.getOrCreateAndWait(data.source, 'private'); const profileKey = data.message.profileKey.toArrayBuffer();
await sender.setProfileKey(profileKey); const sender = ConversationController.getOrCreateAndWait(data.source, 'private');
// TODO: Is `ev.confirm` a `Promise`? Original code returned it: await sender.setProfileKey(profileKey);
return ev.confirm(); // TODO: Is `ev.confirm` a `Promise`? Original code returned it:
} return ev.confirm();
const message = initIncomingMessage(data);
const isDuplicate = await isMessageDuplicate(message);
if (isDuplicate) {
console.log('Received duplicate message', message.idForLogging());
// TODO: Is `ev.confirm` a `Promise`? Original code didnt return it:
return ev.confirm();
}
const { type, id } = data.message.group ?
{ type: 'group', id: data.message.group.id } :
{ type: 'private', id: data.source };
const processedData = Object.assign({}, data, {
message: Object.assign(
{},
data.message,
{
attachments: await Promise.all(
data.message.attachments.map(Attachment.process)
),
}
),
});
await ConversationController.getOrCreateAndWait(id, type);
return message.handleDataMessage(
processedData.message,
ev.confirm,
{ initialLoadComplete }
);
} }
const message = initIncomingMessage(data);
const isDuplicate = await isMessageDuplicate(message);
if (isDuplicate) {
console.log('Received duplicate message', message.idForLogging());
// TODO: Is `ev.confirm` a `Promise`? Original code didnt return it:
return ev.confirm();
}
const { type, id } = data.message.group ?
{ type: 'group', id: data.message.group.id } :
{ type: 'private', id: data.source };
const processedData = Object.assign({}, data, {
message: Object.assign(
{},
data.message,
{
attachments: await Promise.all(
data.message.attachments.map(Attachment.process)
),
}
),
});
await ConversationController.getOrCreateAndWait(id, type);
return message.handleDataMessage(
processedData.message,
ev.confirm,
{ initialLoadComplete }
);
}
/* jshint ignore:end */
/* eslint-disable */
function onSentMessage(ev) { function onSentMessage(ev) {
var now = new Date().getTime(); var now = new Date().getTime();
var data = ev.data; var data = ev.data;