Fix minor style errors
And keep it that way, by making jscs config more opinionated. // FREEBIE
This commit is contained in:
parent
b09cb228f7
commit
173e037fa6
17 changed files with 97 additions and 38 deletions
31
.jscsrc
31
.jscsrc
|
@ -1,4 +1,33 @@
|
|||
{
|
||||
"disallowMixedSpacesAndTabs": true,
|
||||
"disallowTrailingWhitespace": true
|
||||
"disallowTrailingWhitespace": true,
|
||||
"disallowNewlineBeforeBlockStatements": true,
|
||||
"requireCommaBeforeLineBreak": true,
|
||||
"requireSemicolons": true,
|
||||
"requireSpaceBeforeBlockStatements": true,
|
||||
"disallowSpacesInNamedFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
"requireSpacesInNamedFunctionExpression": {
|
||||
"beforeOpeningCurlyBrace": true
|
||||
},
|
||||
"requireCurlyBraces": [
|
||||
"if",
|
||||
"else",
|
||||
"for",
|
||||
"while",
|
||||
"do",
|
||||
"try",
|
||||
"catch"
|
||||
],
|
||||
"requireSpaceAfterKeywords": [
|
||||
"if",
|
||||
"else",
|
||||
"for",
|
||||
"while",
|
||||
"case",
|
||||
"try",
|
||||
"typeof",
|
||||
"return"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -142,6 +142,7 @@ module.exports = function(grunt) {
|
|||
'!js/components.js',
|
||||
'test/**/*.js',
|
||||
'!test/blanket_mocha.js',
|
||||
'!test/test.js',
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
@ -11,11 +11,13 @@
|
|||
thing.__proto__ == StaticByteBufferProto));
|
||||
}
|
||||
function convertToArrayBuffer(thing) {
|
||||
if (thing === undefined)
|
||||
if (thing === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
if (thing === Object(thing)) {
|
||||
if (thing.__proto__ == StaticArrayBufferProto)
|
||||
if (thing.__proto__ == StaticArrayBufferProto) {
|
||||
return thing;
|
||||
}
|
||||
//TODO: Several more cases here...
|
||||
}
|
||||
|
||||
|
@ -23,22 +25,25 @@
|
|||
// Assuming Uint16Array from curve25519
|
||||
var res = new ArrayBuffer(thing.length * 2);
|
||||
var uint = new Uint16Array(res);
|
||||
for (var i = 0; i < thing.length; i++)
|
||||
for (var i = 0; i < thing.length; i++) {
|
||||
uint[i] = thing[i];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
var str;
|
||||
if (isStringable(thing))
|
||||
if (isStringable(thing)) {
|
||||
str = stringObject(thing);
|
||||
else if (typeof thing == "string")
|
||||
} else if (typeof thing == "string") {
|
||||
str = thing;
|
||||
else
|
||||
} else {
|
||||
throw new Error("Tried to convert a non-stringable thing of type " + typeof thing + " to an array buffer");
|
||||
}
|
||||
var res = new ArrayBuffer(str.length);
|
||||
var uint = new Uint8Array(res);
|
||||
for (var i = 0; i < str.length; i++)
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
uint[i] = str.charCodeAt(i);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -168,8 +173,9 @@
|
|||
|
||||
getSession: function(encodedNumber) {
|
||||
console.log('getSession', encodedNumber);
|
||||
if (encodedNumber === null || encodedNumber === undefined)
|
||||
if (encodedNumber === null || encodedNumber === undefined) {
|
||||
throw new Error("Tried to get session for undefined/null number");
|
||||
}
|
||||
return new Promise(function(resolve) {
|
||||
var session = new Session({id: encodedNumber});
|
||||
console.log('fetching session for', encodedNumber);
|
||||
|
@ -182,8 +188,9 @@
|
|||
},
|
||||
putSession: function(encodedNumber, record) {
|
||||
console.log('putSession', encodedNumber);
|
||||
if (encodedNumber === null || encodedNumber === undefined)
|
||||
if (encodedNumber === null || encodedNumber === undefined) {
|
||||
throw new Error("Tried to put session for undefined/null number");
|
||||
}
|
||||
return new Promise(function(resolve) {
|
||||
var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
|
||||
var deviceId = parseInt(textsecure.utils.unencodeNumber(encodedNumber)[1]);
|
||||
|
@ -204,8 +211,9 @@
|
|||
});
|
||||
},
|
||||
getDeviceIds: function(number) {
|
||||
if (number === null || number === undefined)
|
||||
if (number === null || number === undefined) {
|
||||
throw new Error("Tried to get device ids for undefined/null number");
|
||||
}
|
||||
return new Promise(function(resolve) {
|
||||
var sessions = new SessionCollection();
|
||||
sessions.fetchSessionsForNumber(number).always(function() {
|
||||
|
@ -222,8 +230,9 @@
|
|||
});
|
||||
},
|
||||
removeAllSessions: function(number) {
|
||||
if (number === null || number === undefined)
|
||||
if (number === null || number === undefined) {
|
||||
throw new Error("Tried to remove sessions for undefined/null number");
|
||||
}
|
||||
return new Promise(function(resolve) {
|
||||
var sessions = new SessionCollection();
|
||||
sessions.fetchSessionsForNumber(number).always(function() {
|
||||
|
@ -245,8 +254,9 @@
|
|||
|
||||
},
|
||||
getIdentityKey: function(identifier) {
|
||||
if (identifier === null || identifier === undefined)
|
||||
if (identifier === null || identifier === undefined) {
|
||||
throw new Error("Tried to get identity key for undefined/null key");
|
||||
}
|
||||
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
||||
return new Promise(function(resolve) {
|
||||
var identityKey = new IdentityKey({id: number});
|
||||
|
@ -256,8 +266,9 @@
|
|||
});
|
||||
},
|
||||
putIdentityKey: function(identifier, publicKey) {
|
||||
if (identifier === null || identifier === undefined)
|
||||
if (identifier === null || identifier === undefined) {
|
||||
throw new Error("Tried to put identity key for undefined/null key");
|
||||
}
|
||||
if (!(publicKey instanceof ArrayBuffer)) {
|
||||
publicKey = convertToArrayBuffer(publicKey);
|
||||
}
|
||||
|
@ -292,8 +303,9 @@
|
|||
});
|
||||
},
|
||||
getGroup: function(groupId) {
|
||||
if (groupId === null || groupId === undefined)
|
||||
if (groupId === null || groupId === undefined) {
|
||||
throw new Error("Tried to get group for undefined/null id");
|
||||
}
|
||||
return new Promise(function(resolve) {
|
||||
var group = new Group({id: groupId});
|
||||
group.fetch().always(function() {
|
||||
|
@ -302,18 +314,21 @@
|
|||
});
|
||||
},
|
||||
putGroup: function(groupId, group) {
|
||||
if (groupId === null || groupId === undefined)
|
||||
if (groupId === null || groupId === undefined) {
|
||||
throw new Error("Tried to put group key for undefined/null id");
|
||||
if (group === null || group === undefined)
|
||||
}
|
||||
if (group === null || group === undefined) {
|
||||
throw new Error("Tried to put undefined/null group object");
|
||||
}
|
||||
var group = new Group({id: groupId, data: group});
|
||||
return new Promise(function(resolve) {
|
||||
group.save().always(resolve);
|
||||
});
|
||||
},
|
||||
removeGroup: function(groupId) {
|
||||
if (groupId === null || groupId === undefined)
|
||||
if (groupId === null || groupId === undefined) {
|
||||
throw new Error("Tried to remove group key for undefined/null id");
|
||||
}
|
||||
return new Promise(function(resolve) {
|
||||
var group = new Group({id: groupId});
|
||||
group.destroy().always(resolve);
|
||||
|
|
|
@ -39,10 +39,11 @@
|
|||
});
|
||||
|
||||
$('#code').on('change', function() {
|
||||
if (!validateCode())
|
||||
if (!validateCode()) {
|
||||
$('#code').addClass('invalid');
|
||||
else
|
||||
} else {
|
||||
$('#code').removeClass('invalid');
|
||||
}
|
||||
});
|
||||
|
||||
$('#request-voice').click(function() {
|
||||
|
|
|
@ -22,16 +22,18 @@
|
|||
*** Base Storage Routines ***
|
||||
*****************************/
|
||||
put: function(key, value) {
|
||||
if (value === undefined)
|
||||
if (value === undefined) {
|
||||
throw new Error("Tried to store undefined");
|
||||
}
|
||||
var item = items.add({id: key, value: value}, {merge: true});
|
||||
item.save();
|
||||
},
|
||||
|
||||
get: function(key, defaultValue) {
|
||||
var item = items.get("" + key);
|
||||
if (!item)
|
||||
if (!item) {
|
||||
return defaultValue;
|
||||
}
|
||||
return item.get('value');
|
||||
},
|
||||
|
||||
|
|
|
@ -250,7 +250,9 @@
|
|||
},
|
||||
|
||||
openDropped: function(e) {
|
||||
if (e.originalEvent.dataTransfer.types[0] != 'Files') return;
|
||||
if (e.originalEvent.dataTransfer.types[0] != 'Files') {
|
||||
return;
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
@ -260,7 +262,9 @@
|
|||
},
|
||||
|
||||
showArea: function(e) {
|
||||
if (e.originalEvent.dataTransfer.types[0] != 'Files') return;
|
||||
if (e.originalEvent.dataTransfer.types[0] != 'Files') {
|
||||
return;
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
@ -268,7 +272,9 @@
|
|||
},
|
||||
|
||||
hideArea: function(e) {
|
||||
if (e.originalEvent.dataTransfer.types[0] != 'Files') return;
|
||||
if (e.originalEvent.dataTransfer.types[0] != 'Files') {
|
||||
return;
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
|
|
@ -74,7 +74,9 @@
|
|||
|
||||
// TODO: css animation or error notification
|
||||
errors.removeClass('error');
|
||||
setTimeout(function(){ errors.addClass('error'); }, 300);
|
||||
setTimeout(function() {
|
||||
errors.addClass('error');
|
||||
}, 300);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -56,8 +56,9 @@ function assertEqualArrayBuffers(ab1, ab2) {
|
|||
function hexToArrayBuffer(str) {
|
||||
var ret = new ArrayBuffer(str.length / 2);
|
||||
var array = new Uint8Array(ret);
|
||||
for (var i = 0; i < str.length/2; i++)
|
||||
for (var i = 0; i < str.length/2; i++) {
|
||||
array[i] = parseInt(str.substr(i*2, 2), 16);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
sent_at : Date.now(),
|
||||
received_at : Date.now()
|
||||
});
|
||||
message.save().then(done)
|
||||
message.save().then(done);
|
||||
});
|
||||
});
|
||||
after(clearDatabase);
|
||||
|
|
|
@ -101,7 +101,7 @@ describe("AxolotlStore", function() {
|
|||
var promise = Promise.resolve();
|
||||
devices.forEach(function(encodedNumber) {
|
||||
promise = promise.then(function() {
|
||||
return store.putSession(encodedNumber, testRecord + encodedNumber)
|
||||
return store.putSession(encodedNumber, testRecord + encodedNumber);
|
||||
});
|
||||
});
|
||||
promise.then(function() {
|
||||
|
@ -133,7 +133,7 @@ describe("AxolotlStore", function() {
|
|||
var promise = Promise.resolve();
|
||||
devices.forEach(function(encodedNumber) {
|
||||
promise = promise.then(function() {
|
||||
return store.putSession(encodedNumber, testRecord + encodedNumber)
|
||||
return store.putSession(encodedNumber, testRecord + encodedNumber);
|
||||
});
|
||||
});
|
||||
promise.then(function() {
|
||||
|
|
|
@ -25,7 +25,9 @@ describe('TimestampView', function() {
|
|||
|
||||
// Helper to check an absolute TS for an exact match against both views
|
||||
var checkAbs = function(ts, expected_brief, expected_ext) {
|
||||
if (!expected_ext) expected_ext = expected_brief;
|
||||
if (!expected_ext) {
|
||||
expected_ext = expected_brief;
|
||||
}
|
||||
check(brief_view, ts, expected_brief);
|
||||
check(ext_view, ts, expected_ext);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue