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,
|
"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',
|
'!js/components.js',
|
||||||
'test/**/*.js',
|
'test/**/*.js',
|
||||||
'!test/blanket_mocha.js',
|
'!test/blanket_mocha.js',
|
||||||
|
'!test/test.js',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -11,11 +11,13 @@
|
||||||
thing.__proto__ == StaticByteBufferProto));
|
thing.__proto__ == StaticByteBufferProto));
|
||||||
}
|
}
|
||||||
function convertToArrayBuffer(thing) {
|
function convertToArrayBuffer(thing) {
|
||||||
if (thing === undefined)
|
if (thing === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
}
|
||||||
if (thing === Object(thing)) {
|
if (thing === Object(thing)) {
|
||||||
if (thing.__proto__ == StaticArrayBufferProto)
|
if (thing.__proto__ == StaticArrayBufferProto) {
|
||||||
return thing;
|
return thing;
|
||||||
|
}
|
||||||
//TODO: Several more cases here...
|
//TODO: Several more cases here...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,22 +25,25 @@
|
||||||
// Assuming Uint16Array from curve25519
|
// Assuming Uint16Array from curve25519
|
||||||
var res = new ArrayBuffer(thing.length * 2);
|
var res = new ArrayBuffer(thing.length * 2);
|
||||||
var uint = new Uint16Array(res);
|
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];
|
uint[i] = thing[i];
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
var str;
|
var str;
|
||||||
if (isStringable(thing))
|
if (isStringable(thing)) {
|
||||||
str = stringObject(thing);
|
str = stringObject(thing);
|
||||||
else if (typeof thing == "string")
|
} else if (typeof thing == "string") {
|
||||||
str = thing;
|
str = thing;
|
||||||
else
|
} else {
|
||||||
throw new Error("Tried to convert a non-stringable thing of type " + typeof thing + " to an array buffer");
|
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 res = new ArrayBuffer(str.length);
|
||||||
var uint = new Uint8Array(res);
|
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);
|
uint[i] = str.charCodeAt(i);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,8 +173,9 @@
|
||||||
|
|
||||||
getSession: function(encodedNumber) {
|
getSession: function(encodedNumber) {
|
||||||
console.log('getSession', 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");
|
throw new Error("Tried to get session for undefined/null number");
|
||||||
|
}
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
var session = new Session({id: encodedNumber});
|
var session = new Session({id: encodedNumber});
|
||||||
console.log('fetching session for', encodedNumber);
|
console.log('fetching session for', encodedNumber);
|
||||||
|
@ -182,8 +188,9 @@
|
||||||
},
|
},
|
||||||
putSession: function(encodedNumber, record) {
|
putSession: function(encodedNumber, record) {
|
||||||
console.log('putSession', encodedNumber);
|
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");
|
throw new Error("Tried to put session for undefined/null number");
|
||||||
|
}
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
|
var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
|
||||||
var deviceId = parseInt(textsecure.utils.unencodeNumber(encodedNumber)[1]);
|
var deviceId = parseInt(textsecure.utils.unencodeNumber(encodedNumber)[1]);
|
||||||
|
@ -204,8 +211,9 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getDeviceIds: function(number) {
|
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");
|
throw new Error("Tried to get device ids for undefined/null number");
|
||||||
|
}
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
var sessions = new SessionCollection();
|
var sessions = new SessionCollection();
|
||||||
sessions.fetchSessionsForNumber(number).always(function() {
|
sessions.fetchSessionsForNumber(number).always(function() {
|
||||||
|
@ -222,13 +230,14 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
removeAllSessions: function(number) {
|
removeAllSessions: function(number) {
|
||||||
if (number === null || number === undefined)
|
if (number === null || number === undefined) {
|
||||||
throw new Error("Tried to remove sessions for undefined/null number");
|
throw new Error("Tried to remove sessions for undefined/null number");
|
||||||
|
}
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
var sessions = new SessionCollection();
|
var sessions = new SessionCollection();
|
||||||
sessions.fetchSessionsForNumber(number).always(function() {
|
sessions.fetchSessionsForNumber(number).always(function() {
|
||||||
var promises = [];
|
var promises = [];
|
||||||
while(sessions.length > 0) {
|
while (sessions.length > 0) {
|
||||||
promises.push(new Promise(function(res) {
|
promises.push(new Promise(function(res) {
|
||||||
sessions.pop().destroy().then(res);
|
sessions.pop().destroy().then(res);
|
||||||
}));
|
}));
|
||||||
|
@ -245,8 +254,9 @@
|
||||||
|
|
||||||
},
|
},
|
||||||
getIdentityKey: function(identifier) {
|
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");
|
throw new Error("Tried to get identity key for undefined/null key");
|
||||||
|
}
|
||||||
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
var identityKey = new IdentityKey({id: number});
|
var identityKey = new IdentityKey({id: number});
|
||||||
|
@ -256,8 +266,9 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
putIdentityKey: function(identifier, publicKey) {
|
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");
|
throw new Error("Tried to put identity key for undefined/null key");
|
||||||
|
}
|
||||||
if (!(publicKey instanceof ArrayBuffer)) {
|
if (!(publicKey instanceof ArrayBuffer)) {
|
||||||
publicKey = convertToArrayBuffer(publicKey);
|
publicKey = convertToArrayBuffer(publicKey);
|
||||||
}
|
}
|
||||||
|
@ -292,8 +303,9 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getGroup: function(groupId) {
|
getGroup: function(groupId) {
|
||||||
if (groupId === null || groupId === undefined)
|
if (groupId === null || groupId === undefined) {
|
||||||
throw new Error("Tried to get group for undefined/null id");
|
throw new Error("Tried to get group for undefined/null id");
|
||||||
|
}
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
var group = new Group({id: groupId});
|
var group = new Group({id: groupId});
|
||||||
group.fetch().always(function() {
|
group.fetch().always(function() {
|
||||||
|
@ -302,18 +314,21 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
putGroup: function(groupId, group) {
|
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");
|
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");
|
throw new Error("Tried to put undefined/null group object");
|
||||||
|
}
|
||||||
var group = new Group({id: groupId, data: group});
|
var group = new Group({id: groupId, data: group});
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
group.save().always(resolve);
|
group.save().always(resolve);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
removeGroup: function(groupId) {
|
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");
|
throw new Error("Tried to remove group key for undefined/null id");
|
||||||
|
}
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
var group = new Group({id: groupId});
|
var group = new Group({id: groupId});
|
||||||
group.destroy().always(resolve);
|
group.destroy().always(resolve);
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
var log = new DebugLog();
|
var log = new DebugLog();
|
||||||
if (window.console) {
|
if (window.console) {
|
||||||
console._log = console.log;
|
console._log = console.log;
|
||||||
console.log = function(){
|
console.log = function() {
|
||||||
console._log.apply(this, arguments);
|
console._log.apply(this, arguments);
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var args = Array.prototype.slice.call(arguments);
|
||||||
var str = args.join(' ').replace(PHONE_REGEX, "+[REDACTED]$1");
|
var str = args.join(' ').replace(PHONE_REGEX, "+[REDACTED]$1");
|
||||||
|
|
|
@ -181,7 +181,7 @@
|
||||||
var conversationId = this.id;
|
var conversationId = this.id;
|
||||||
Whisper.Notifications.remove(
|
Whisper.Notifications.remove(
|
||||||
Whisper.Notifications.models.filter(
|
Whisper.Notifications.models.filter(
|
||||||
function(model){
|
function(model) {
|
||||||
return model.attributes.conversationId===conversationId;
|
return model.attributes.conversationId===conversationId;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -400,7 +400,7 @@
|
||||||
if (this.length === 0) {
|
if (this.length === 0) {
|
||||||
// fetch the most recent messages first
|
// fetch the most recent messages first
|
||||||
upper = Number.MAX_VALUE;
|
upper = Number.MAX_VALUE;
|
||||||
} else {
|
} else {
|
||||||
// not our first rodeo, fetch older messages.
|
// not our first rodeo, fetch older messages.
|
||||||
upper = this.at(0).get('received_at');
|
upper = this.at(0).get('received_at');
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,10 +39,11 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#code').on('change', function() {
|
$('#code').on('change', function() {
|
||||||
if (!validateCode())
|
if (!validateCode()) {
|
||||||
$('#code').addClass('invalid');
|
$('#code').addClass('invalid');
|
||||||
else
|
} else {
|
||||||
$('#code').removeClass('invalid');
|
$('#code').removeClass('invalid');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#request-voice').click(function() {
|
$('#request-voice').click(function() {
|
||||||
|
|
|
@ -22,16 +22,18 @@
|
||||||
*** Base Storage Routines ***
|
*** Base Storage Routines ***
|
||||||
*****************************/
|
*****************************/
|
||||||
put: function(key, value) {
|
put: function(key, value) {
|
||||||
if (value === undefined)
|
if (value === undefined) {
|
||||||
throw new Error("Tried to store undefined");
|
throw new Error("Tried to store undefined");
|
||||||
|
}
|
||||||
var item = items.add({id: key, value: value}, {merge: true});
|
var item = items.add({id: key, value: value}, {merge: true});
|
||||||
item.save();
|
item.save();
|
||||||
},
|
},
|
||||||
|
|
||||||
get: function(key, defaultValue) {
|
get: function(key, defaultValue) {
|
||||||
var item = items.get("" + key);
|
var item = items.get("" + key);
|
||||||
if (!item)
|
if (!item) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
}
|
||||||
return item.get('value');
|
return item.get('value');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -231,7 +231,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
replace_colons: function(str) {
|
replace_colons: function(str) {
|
||||||
return str.replace(emoji.rx_colons, function(m){
|
return str.replace(emoji.rx_colons, function(m) {
|
||||||
var idx = m.substr(1, m.length-2);
|
var idx = m.substr(1, m.length-2);
|
||||||
var val = emoji.map.colons[idx];
|
var val = emoji.map.colons[idx];
|
||||||
if (val) {
|
if (val) {
|
||||||
|
|
|
@ -250,7 +250,9 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
openDropped: function(e) {
|
openDropped: function(e) {
|
||||||
if (e.originalEvent.dataTransfer.types[0] != 'Files') return;
|
if (e.originalEvent.dataTransfer.types[0] != 'Files') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -260,7 +262,9 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
showArea: function(e) {
|
showArea: function(e) {
|
||||||
if (e.originalEvent.dataTransfer.types[0] != 'Files') return;
|
if (e.originalEvent.dataTransfer.types[0] != 'Files') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -268,7 +272,9 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
hideArea: function(e) {
|
hideArea: function(e) {
|
||||||
if (e.originalEvent.dataTransfer.types[0] != 'Files') return;
|
if (e.originalEvent.dataTransfer.types[0] != 'Files') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
|
@ -74,7 +74,9 @@
|
||||||
|
|
||||||
// TODO: css animation or error notification
|
// TODO: css animation or error notification
|
||||||
errors.removeClass('error');
|
errors.removeClass('error');
|
||||||
setTimeout(function(){ errors.addClass('error'); }, 300);
|
setTimeout(function() {
|
||||||
|
errors.addClass('error');
|
||||||
|
}, 300);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
this.$el.closest('body').append(dialog.el);
|
this.$el.closest('body').append(dialog.el);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
i18n_with_link: function(message, href){
|
i18n_with_link: function(message, href) {
|
||||||
var attrs = 'class="link" href="' + encodeURI(href) + '" target="_blank"';
|
var attrs = 'class="link" href="' + encodeURI(href) + '" target="_blank"';
|
||||||
return i18n(message, attrs);
|
return i18n(message, attrs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,9 @@ function assertEqualArrayBuffers(ab1, ab2) {
|
||||||
function hexToArrayBuffer(str) {
|
function hexToArrayBuffer(str) {
|
||||||
var ret = new ArrayBuffer(str.length / 2);
|
var ret = new ArrayBuffer(str.length / 2);
|
||||||
var array = new Uint8Array(ret);
|
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);
|
array[i] = parseInt(str.substr(i*2, 2), 16);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@
|
||||||
sent_at : Date.now(),
|
sent_at : Date.now(),
|
||||||
received_at : Date.now()
|
received_at : Date.now()
|
||||||
});
|
});
|
||||||
message.save().then(done)
|
message.save().then(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
after(clearDatabase);
|
after(clearDatabase);
|
||||||
|
|
|
@ -101,7 +101,7 @@ describe("AxolotlStore", function() {
|
||||||
var promise = Promise.resolve();
|
var promise = Promise.resolve();
|
||||||
devices.forEach(function(encodedNumber) {
|
devices.forEach(function(encodedNumber) {
|
||||||
promise = promise.then(function() {
|
promise = promise.then(function() {
|
||||||
return store.putSession(encodedNumber, testRecord + encodedNumber)
|
return store.putSession(encodedNumber, testRecord + encodedNumber);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
|
@ -133,7 +133,7 @@ describe("AxolotlStore", function() {
|
||||||
var promise = Promise.resolve();
|
var promise = Promise.resolve();
|
||||||
devices.forEach(function(encodedNumber) {
|
devices.forEach(function(encodedNumber) {
|
||||||
promise = promise.then(function() {
|
promise = promise.then(function() {
|
||||||
return store.putSession(encodedNumber, testRecord + encodedNumber)
|
return store.putSession(encodedNumber, testRecord + encodedNumber);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
describe('ListView', function() {
|
describe('ListView', function() {
|
||||||
var collection;
|
var collection;
|
||||||
|
|
||||||
beforeEach(function(){
|
beforeEach(function() {
|
||||||
collection = new Backbone.Collection();
|
collection = new Backbone.Collection();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,9 @@ describe('TimestampView', function() {
|
||||||
|
|
||||||
// Helper to check an absolute TS for an exact match against both views
|
// Helper to check an absolute TS for an exact match against both views
|
||||||
var checkAbs = function(ts, expected_brief, expected_ext) {
|
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(brief_view, ts, expected_brief);
|
||||||
check(ext_view, ts, expected_ext);
|
check(ext_view, ts, expected_ext);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue