Add eslint rule to enforce curlys, run eslint --fix to automatically apply this rule and add swapfiles to gitignore

pull/368/head
Beaudan 5 years ago
parent 78537fc53f
commit 63396669bc

@ -21,6 +21,9 @@ module.exports = {
},
],
// Enforce curlies always
curly: 'error',
// prevents us from accidentally checking in exclusive tests (`.only`):
'mocha/no-exclusive-tests': 'error',

3
.gitignore vendored

@ -30,3 +30,6 @@ test/test.js
# React / TypeScript
ts/**/*.js
ts/protobuf/*.d.ts
# Swapfiles
**/*.swp

@ -1059,8 +1059,9 @@
// Check if the pubkey length is 33 and leading with 05 or of length 32
const len = this.id.length;
if ((len !== 33 * 2 || !/^05/.test(this.id)) && len !== 32 * 2)
if ((len !== 33 * 2 || !/^05/.test(this.id)) && len !== 32 * 2) {
return 'Invalid Pubkey Format';
}
this.set({ id: this.id });
return null;
@ -1421,8 +1422,9 @@
messageType,
success,
}) {
if (success && messageType === 'friend-request')
if (success && messageType === 'friend-request') {
await this.onFriendRequestSent();
}
await Promise.all(
(failoverNumbers || []).map(async number => {
const conversation = ConversationController.get(number);
@ -2342,8 +2344,9 @@
notify(message) {
if (message.isFriendRequest()) {
if (this.hasSentFriendRequest())
if (this.hasSentFriendRequest()) {
return this.notifyFriendRequest(message.get('source'), 'accepted');
}
return this.notifyFriendRequest(message.get('source'), 'requested');
}
if (!message.isIncoming()) return Promise.resolve();
@ -2380,8 +2383,9 @@
async notifyFriendRequest(source, type) {
// Data validation
if (!source) throw new Error('Invalid source');
if (!['accepted', 'requested'].includes(type))
if (!['accepted', 'requested'].includes(type)) {
throw new Error('Type must be accepted or requested.');
}
// Call the notification on the right conversation
let conversation = this;

@ -2047,9 +2047,9 @@
if (message.get('unread')) {
// Need to do this here because the conversation has already changed states
if (autoAccept)
if (autoAccept) {
await conversation.notifyFriendRequest(source, 'accepted');
else await conversation.notify(message);
} else await conversation.notify(message);
}
confirm();

@ -364,8 +364,9 @@ class LokiMessageAPI {
const promises = [];
for (let i = 0; i < numConnections; i += 1)
for (let i = 0; i < numConnections; i += 1) {
promises.push(this.openRetrieveConnection(stopPolling, callback));
}
// blocks until all snodes in our swarms have been removed from the list
// or if there is network issues (ENOUTFOUND due to lokinet)

@ -28,10 +28,12 @@ const Uint8ArrayToString = _call(new Uint8Array());
function _getString(thing) {
if (typeof thing !== 'string') {
if (_call(thing) === Uint8ArrayToString)
if (_call(thing) === Uint8ArrayToString) {
return String.fromCharCode.apply(null, thing);
if (_call(thing) === ArrayBufferToString)
}
if (_call(thing) === ArrayBufferToString) {
return _getString(new Uint8Array(thing));
}
}
return thing;
}

@ -100,8 +100,9 @@
this.typeahead_view.collection.forEach(c => c.updateLastMessage());
// Show the new contact view if we already have results
if (this.typeahead_view.collection.length === 0)
if (this.typeahead_view.collection.length === 0) {
this.new_contact_view.$el.show();
}
})
);
/* eslint-enable more/no-then */

@ -76,8 +76,9 @@ function randomString(length) {
let text = '';
const possible =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < length; i += 1)
for (let i = 0; i < length; i += 1) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}

@ -40,8 +40,9 @@ describe('Storage', () => {
testKeyArray.byteLength,
newBundle.signedKey.byteLength
);
for (let i = 0; i !== testKeyArray.byteLength; i += 1)
for (let i = 0; i !== testKeyArray.byteLength; i += 1) {
assert.strictEqual(testKeyArray[i], newBundle.signedKey[i]);
}
});
it('should return the same prekey bundle after creating a contact', async () => {

@ -15,12 +15,15 @@ const StaticArrayBufferProto = new ArrayBuffer().__proto__;
const StaticUint8ArrayProto = new Uint8Array().__proto__;
function getString(thing) {
if (thing === Object(thing)) {
if (thing.__proto__ === StaticUint8ArrayProto)
if (thing.__proto__ === StaticUint8ArrayProto) {
return String.fromCharCode.apply(null, thing);
if (thing.__proto__ === StaticArrayBufferProto)
}
if (thing.__proto__ === StaticArrayBufferProto) {
return getString(new Uint8Array(thing));
if (thing.__proto__ === StaticByteBufferProto)
}
if (thing.__proto__ === StaticByteBufferProto) {
return thing.toString('binary');
}
}
return thing;
}
@ -51,8 +54,9 @@ window.textsecure.utils = (() => {
if (getStringable(thing)) return getString(thing);
else if (thing instanceof Array) {
const res = [];
for (let i = 0; i < thing.length; i += 1)
for (let i = 0; i < thing.length; i += 1) {
res[i] = ensureStringed(thing[i]);
}
return res;
} else if (thing === Object(thing)) {
const res = {};

@ -1130,28 +1130,36 @@ MessageReceiver.prototype.extend({
async innerHandleContentMessage(envelope, plaintext) {
const content = textsecure.protobuf.Content.decode(plaintext);
if (content.preKeyBundleMessage)
if (content.preKeyBundleMessage) {
await this.savePreKeyBundleMessage(
envelope.source,
content.preKeyBundleMessage
);
if (content.lokiAddressMessage)
}
if (content.lokiAddressMessage) {
return this.handleLokiAddressMessage(
envelope,
content.lokiAddressMessage
);
if (content.syncMessage)
}
if (content.syncMessage) {
return this.handleSyncMessage(envelope, content.syncMessage);
if (content.dataMessage)
}
if (content.dataMessage) {
return this.handleDataMessage(envelope, content.dataMessage);
if (content.nullMessage)
}
if (content.nullMessage) {
return this.handleNullMessage(envelope, content.nullMessage);
if (content.callMessage)
}
if (content.callMessage) {
return this.handleCallMessage(envelope, content.callMessage);
if (content.receiptMessage)
}
if (content.receiptMessage) {
return this.handleReceiptMessage(envelope, content.receiptMessage);
if (content.typingMessage)
}
if (content.typingMessage) {
return this.handleTypingMessage(envelope, content.typingMessage);
}
return null;
},

@ -385,12 +385,13 @@ OutgoingMessage.prototype = {
error.name === 'HTTPError' &&
(error.code === 410 || error.code === 409)
) {
if (!recurse)
if (!recurse) {
return this.registerError(
number,
'Hit retry limit attempting to reload device list',
error
);
}
let p;
if (error.code === 409) {

@ -51,8 +51,9 @@ window.assertEqualArrayBuffers = (ab1, ab2) => {
window.hexToArrayBuffer = str => {
const ret = new ArrayBuffer(str.length / 2);
const array = new Uint8Array(ret);
for (let i = 0; i < str.length / 2; i += 1)
for (let i = 0; i < str.length / 2; i += 1) {
array[i] = parseInt(str.substr(i * 2, 2), 16);
}
return ret;
};

@ -42,8 +42,9 @@ const fakeAPI = {
msg.timestamp === undefined ||
msg.relay !== undefined ||
msg.destination !== undefined
)
) {
throw new Error('Invalid message');
}
messagesSentMap[
`${destination}.${messageArray[i].destinationDeviceId}`

@ -16,21 +16,24 @@ SignalProtocolStore.prototype = {
value === undefined ||
key === null ||
value === null
)
) {
throw new Error('Tried to store undefined/null');
}
this.store[key] = value;
},
get(key, defaultValue) {
if (key === null || key === undefined)
if (key === null || key === undefined) {
throw new Error('Tried to get value for undefined/null key');
}
if (key in this.store) {
return this.store[key];
}
return defaultValue;
},
remove(key) {
if (key === null || key === undefined)
if (key === null || key === undefined) {
throw new Error('Tried to remove value for undefined/null key');
}
delete this.store[key];
},
@ -48,15 +51,17 @@ SignalProtocolStore.prototype = {
return Promise.resolve(identityKey === trusted);
},
loadIdentityKey(identifier) {
if (identifier === null || identifier === undefined)
if (identifier === null || identifier === undefined) {
throw new Error('Tried to get identity key for undefined/null key');
}
return new Promise(resolve => {
resolve(this.get(`identityKey${identifier}`));
});
},
saveIdentity(identifier, identityKey) {
if (identifier === null || identifier === undefined)
if (identifier === null || identifier === undefined) {
throw new Error('Tried to put identity key for undefined/null key');
}
return new Promise(resolve => {
const existing = this.get(`identityKey${identifier}`);
this.put(`identityKey${identifier}`, identityKey);

@ -43,13 +43,15 @@ InMemorySignalProtocolStore.prototype = {
value === undefined ||
key === null ||
value === null
)
) {
throw new Error('Tried to store undefined/null');
}
this.store[key] = value;
},
get(key, defaultValue) {
if (key === null || key === undefined)
if (key === null || key === undefined) {
throw new Error('Tried to get value for undefined/null key');
}
if (key in this.store) {
return this.store[key];
}
@ -57,8 +59,9 @@ InMemorySignalProtocolStore.prototype = {
return defaultValue;
},
remove(key) {
if (key === null || key === undefined)
if (key === null || key === undefined) {
throw new Error('Tried to remove value for undefined/null key');
}
delete this.store[key];
},

Loading…
Cancel
Save