Skip to content

Commit

Permalink
Merge pull request #6458 from RocketChat/improvements/eslint
Browse files Browse the repository at this point in the history
Add ESLint rule `one-var`
  • Loading branch information
engelgabriel authored Mar 24, 2017
2 parents 47d5a17 + 4e889bc commit e2a1a1e
Show file tree
Hide file tree
Showing 29 changed files with 155 additions and 154 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"vars": "all",
"args": "after-used"
}],
"one-var": [2, "never"],
"no-lonely-if": 2,
"no-trailing-spaces": 2,
"complexity": [1, 31],
Expand Down
5 changes: 2 additions & 3 deletions client/startup/userSetUtcOffset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import moment from 'moment';

Meteor.startup(function() {
Tracker.autorun(function() {
var user, utcOffset;
user = Meteor.user();
const user = Meteor.user();
if (user && user.statusConnection === 'online') {
utcOffset = moment().utcOffset() / 60;
const utcOffset = moment().utcOffset() / 60;
if (user.utcOffset !== utcOffset) {
Meteor.call('userSetUtcOffset', utcOffset);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/fileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ if (UploadFS) {

onRead(fileId, file, req, res) {
if (RocketChat.settings.get('FileUpload_ProtectFiles')) {
let uid, token;
let uid;
let token;

if (req && req.headers && req.headers.cookie) {
const rawCookies = req.headers.cookie;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* globals Slingshot, FileUpload, AWS, SystemLogger */
const crypto = Npm.require('crypto');

let S3accessKey, S3secretKey, S3expiryTimeSpan;
let S3accessKey;
let S3secretKey;
let S3expiryTimeSpan;

const generateURL = function(file) {
if (!file || !file.s3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ ExtractRange.prototype._transform = function(chunk, enc, cb) {
} else if (this.bytes_read + chunk.length < this.start) {
// this chunk is still before the start byte
} else {
let start, stop;
let start;
let stop;

if (this.start <= this.bytes_read) {
start = 0;
} else {
Expand Down
6 changes: 4 additions & 2 deletions packages/rocketchat-file-upload/server/lib/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ WebApp.connectHandlers.use('/file-upload/', function(req, res, next) {

if (file) {
if (!Meteor.settings.public.sandstorm && protectedFiles) {
let rawCookies, ref, token, uid;
let rawCookies;
let token;
let uid;
const cookie = new Cookies();

if ((typeof req !== 'undefined' && req !== null ? (ref = req.headers) != null ? ref.cookie : void 0 : void 0) != null) {
if (req.headers && req.headers.cookie != null) {
rawCookies = req.headers.cookie;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const crypto = Npm.require('crypto');
let protectedFiles, S3accessKey, S3secretKey, S3expiryTimeSpan;
let protectedFiles;
let S3accessKey;
let S3secretKey;
let S3expiryTimeSpan;

RocketChat.settings.get('FileUpload_ProtectFiles', function(key, value) {
protectedFiles = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ Template.integrationsOutgoing.events({
return toastr.error(TAPi18n.__('You_should_inform_one_url_at_least'));
}

let triggerWords, triggerWordAnywhere;
let triggerWords;
let triggerWordAnywhere;
if (RocketChat.integrations.outgoingEvents[event].use.triggerWords) {
triggerWords = $('[name=triggerWords]').val().trim();
triggerWords = triggerWords.split(',').filter((word) => word.trim() !== '');
Expand All @@ -311,10 +312,11 @@ Template.integrationsOutgoing.events({
}
}

let retryCount, retryDelay;
let retryCount;
let retryDelay;
if (retryFailedCalls === '1') {
retryCount = parseInt($('[name=retryCount]').val().trim());
retryDelay: $('[name=retryDelay]').val().trim();
retryDelay = $('[name=retryDelay]').val().trim();
}

const integration = {
Expand Down
7 changes: 3 additions & 4 deletions packages/rocketchat-lib/lib/fileUploadRestrictions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ RocketChat.fileUploadMediaWhiteList = function() {
};

RocketChat.fileUploadIsValidContentType = function(type) {
var list, wildCardGlob, wildcards;
list = RocketChat.fileUploadMediaWhiteList();
const list = RocketChat.fileUploadMediaWhiteList();
if (!list || _.contains(list, type)) {
return true;
} else {
wildCardGlob = '/*';
wildcards = _.filter(list, function(item) {
const wildCardGlob = '/*';
const wildcards = _.filter(list, function(item) {
return item.indexOf(wildCardGlob) > 0;
});
if (_.contains(wildcards, type.replace(/(\/.*)$/, wildCardGlob))) {
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-lib/server/functions/saveUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ RocketChat.saveUser = function(userId, userData) {
const header = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Header') || '');
const footer = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Footer') || '');

let subject, html;
let subject;
let html;

if (RocketChat.settings.get('Accounts_UserAddedEmail_Customized')) {
subject = RocketChat.settings.get('Accounts_UserAddedEmailSubject');
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-lib/server/functions/setUserAvatar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RocketChat.setUserAvatar = function(user, dataURI, contentType, service) {
let encoding, image;
let encoding;
let image;

if (service === 'initials') {
return RocketChat.models.Users.setAvatarOrigin(user._id, service);
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-lib/server/lib/PushNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class PushNotification {
}

hash(str) {
let hash = 0,
i = str.length;
let hash = 0;
let i = str.length;

while (i) {
hash = ((hash << 5) - hash) + str.charCodeAt(--i);
Expand Down
10 changes: 4 additions & 6 deletions packages/rocketchat-lib/server/lib/notifyUsersOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
// Update the other subscriptions
RocketChat.models.Subscriptions.incUnreadOfDirectForRoomIdExcludingUserId(message.rid, message.u._id, 1);
} else {
var mentionIds, toAll, highlightsIds, highlights;

mentionIds = [];
highlightsIds = [];
toAll = false;
highlights = RocketChat.models.Users.findUsersByUsernamesWithHighlights(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch();
let toAll = false;
const mentionIds = [];
const highlightsIds = [];
const highlights = RocketChat.models.Users.findUsersByUsernamesWithHighlights(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch();

if (message.mentions != null) {
message.mentions.forEach(function(mention) {
Expand Down
5 changes: 3 additions & 2 deletions packages/rocketchat-lib/server/lib/sendEmailOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
return message;
}

var emailSubject, usersToSendEmail = {};
var directMessage = room.t === 'd';
let emailSubject;
const usersToSendEmail = {};
const directMessage = room.t === 'd';

if (directMessage) {
usersToSendEmail[message.rid.replace(message.u._id, '')] = 1;
Expand Down
60 changes: 23 additions & 37 deletions packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
/*
Increment unread couter if direct messages
*/
var indexOf = [].indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) {
if (i in this && this[i] === item) {
return i;
}
}
return -1;
};

var settings, desktopMentionIds, i, j, len, len1, highlights, mentionIds, highlightsIds, usersWithHighlights, mobileMentionIds, ref, ref1, toAll, toHere, userIdsToNotify, userIdsToPushNotify, userOfMention, userOfMentionId, usersOfDesktopMentions, usersOfMentionId, usersOfMentionItem, usersOfMobileMentions;
const settings = {};

/**
* Checks if a given user can be notified
Expand Down Expand Up @@ -67,8 +58,6 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
return has;
}

settings = {};

settings.alwaysNotifyDesktopUsers = [];
settings.dontNotifyDesktopUsers = [];
settings.alwaysNotifyMobileUsers = [];
Expand All @@ -90,11 +79,11 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
settings.desktopNotificationDurations[subscription.u._id] = subscription.desktopNotificationDuration;
});

userIdsToNotify = [];
userIdsToPushNotify = [];
usersWithHighlights = [];
let userIdsToNotify = [];
let userIdsToPushNotify = [];
const usersWithHighlights = [];

highlights = RocketChat.models.Users.findUsersByUsernamesWithHighlights(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch();
const highlights = RocketChat.models.Users.findUsersByUsernamesWithHighlights(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch();

highlights.forEach(function(user) {
if (messageContainsHighlight(message, user.settings.preferences.highlights)) {
Expand All @@ -120,9 +109,9 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
push_room = '';
}

if ((room.t == null) || room.t === 'd') {
userOfMentionId = message.rid.replace(message.u._id, '');
userOfMention = RocketChat.models.Users.findOne({
if (room.t == null || room.t === 'd') {
const userOfMentionId = message.rid.replace(message.u._id, '');
const userOfMention = RocketChat.models.Users.findOne({
_id: userOfMentionId
}, {
fields: {
Expand Down Expand Up @@ -174,19 +163,19 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
}

} else {
mentionIds = [];
if ((ref = message.mentions) != null) {
ref.forEach(function(mention) {
const mentionIds = [];
if (message.mentions != null) {
message.mentions.forEach(function(mention) {
return mentionIds.push(mention._id);
});
}
toAll = mentionIds.indexOf('all') > -1;
toHere = mentionIds.indexOf('here') > -1;
const toAll = mentionIds.indexOf('all') > -1;
const toHere = mentionIds.indexOf('here') > -1;
if (mentionIds.length > 0 || settings.alwaysNotifyDesktopUsers.length > 0) {
desktopMentionIds = _.union(mentionIds, settings.alwaysNotifyDesktopUsers);
let desktopMentionIds = _.union(mentionIds, settings.alwaysNotifyDesktopUsers);
desktopMentionIds = _.difference(desktopMentionIds, settings.dontNotifyDesktopUsers);

usersOfDesktopMentions = RocketChat.models.Users.find({
let usersOfDesktopMentions = RocketChat.models.Users.find({
_id: {
$in: desktopMentionIds
}
Expand All @@ -205,8 +194,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
});
}
};
for (i = 0, len = usersOfDesktopMentions.length; i < len; i++) {
usersOfMentionItem = usersOfDesktopMentions[i];
for (const usersOfMentionItem of usersOfDesktopMentions) {
if (room.usernames.indexOf(usersOfMentionItem.username) === -1) {
callJoin(usersOfMentionItem);
}
Expand All @@ -223,10 +211,10 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
}

if (mentionIds.length > 0 || settings.alwaysNotifyMobileUsers.length > 0) {
mobileMentionIds = _.union(mentionIds, settings.alwaysNotifyMobileUsers);
let mobileMentionIds = _.union(mentionIds, settings.alwaysNotifyMobileUsers);
mobileMentionIds = _.difference(mobileMentionIds, settings.dontNotifyMobileUsers);

usersOfMobileMentions = RocketChat.models.Users.find({
let usersOfMobileMentions = RocketChat.models.Users.find({
_id: {
$in: mobileMentionIds
}
Expand All @@ -249,7 +237,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
}), '_id');
}

if ((toAll || toHere) && ((ref1 = room.usernames) != null ? ref1.length : void 0) > 0) {
if ((toAll || toHere) && room.usernames && room.usernames.length > 0) {
RocketChat.models.Users.find({
username: {
$in: room.usernames
Expand All @@ -265,18 +253,17 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
statusConnection: 1
}
}).forEach(function(user) {
var ref2, ref3, ref4;
if (((ref2 = user.status) === 'online' || ref2 === 'away' || ref2 === 'busy') && (ref3 = user._id, indexOf.call(settings.dontNotifyDesktopUsers, ref3) < 0)) {
if (['online', 'away', 'busy'].includes(user.status) && (settings.dontNotifyDesktopUsers || []).includes(user._id) === false) {
userIdsToNotify.push(user._id);
}
if (toAll && user.statusConnection !== 'online' && (ref4 = user._id, indexOf.call(settings.dontNotifyMobileUsers, ref4) < 0)) {
if (toAll && user.statusConnection !== 'online' && (settings.dontNotifyMobileUsers || []).includes(user._id) === false) {
return userIdsToPushNotify.push(user._id);
}
});
}

if (usersWithHighlights.length > 0) {
highlightsIds = _.pluck(usersWithHighlights, '_id');
const highlightsIds = _.pluck(usersWithHighlights, '_id');
userIdsToNotify = userIdsToNotify.concat(highlightsIds);
userIdsToPushNotify = userIdsToPushNotify.concat(highlightsIds);
}
Expand All @@ -285,8 +272,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
userIdsToPushNotify = _.without(_.compact(_.unique(userIdsToPushNotify)), message.u._id);

if (userIdsToNotify.length > 0) {
for (j = 0, len1 = userIdsToNotify.length; j < len1; j++) {
usersOfMentionId = userIdsToNotify[j];
for (const usersOfMentionId of userIdsToNotify) {
let title = '@' + user.username;
if (room.name) {
title += ' @ #' + room.name;
Expand Down
12 changes: 9 additions & 3 deletions packages/rocketchat-lib/server/methods/updateMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ Meteor.methods({

const blockEditInMinutes = RocketChat.settings.get('Message_AllowEditing_BlockEditInMinutes');
if (Match.test(blockEditInMinutes, Number) && blockEditInMinutes !== 0) {
let currentTsDiff, msgTs;
if (Match.test(originalMessage.ts, Number)) { msgTs = moment(originalMessage.ts); }
if (msgTs) { currentTsDiff = moment().diff(msgTs, 'minutes'); }
let currentTsDiff;
let msgTs;

if (Match.test(originalMessage.ts, Number)) {
msgTs = moment(originalMessage.ts);
}
if (msgTs) {
currentTsDiff = moment().diff(msgTs, 'minutes');
}
if (currentTsDiff > blockEditInMinutes) {
throw new Meteor.Error('error-message-editing-blocked', 'Message editing is blocked', { method: 'updateMessage' });
}
Expand Down
10 changes: 5 additions & 5 deletions packages/rocketchat-livechat/app/client/views/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ Template.messages.onRendered(function() {
});

Template.messages.onRendered(function() {
var messages, newMessage, onscroll, template;
messages = this.find('.messages');
newMessage = this.find('.new-message');
template = this;
const messages = this.find('.messages');
const newMessage = this.find('.new-message');
const template = this;

if (messages) {
onscroll = _.throttle(function() {
const onscroll = _.throttle(function() {
template.atBottom = messages.scrollTop >= messages.scrollHeight - messages.clientHeight;
}, 200);
Meteor.setInterval(function() {
Expand Down
5 changes: 2 additions & 3 deletions packages/rocketchat-livechat/app/client/views/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Template.register.helpers({

Template.register.events({
'submit #livechat-registration'(e, instance) {
var $email, $name;
e.preventDefault();

const start = () => {
Expand All @@ -33,8 +32,8 @@ Template.register.events({
}
};

$name = instance.$('input[name=name]');
$email = instance.$('input[name=email]');
const $name = instance.$('input[name=name]');
const $email = instance.$('input[name=email]');
if (!($name.val().trim() && $email.val().trim())) {
return instance.showError(TAPi18n.__('Please_fill_name_and_email'));
} else {
Expand Down
8 changes: 5 additions & 3 deletions packages/rocketchat-message-snippet/server/requests.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* global Cookies */
WebApp.connectHandlers.use('/snippet/download', function(req, res) {
var cookie, rawCookies, ref, token, uid;
cookie = new Cookies();
let rawCookies;
let token;
let uid;
const cookie = new Cookies();

if ((typeof req !== 'undefined' && req !== null ? (ref = req.headers) !== null ? ref.cookie : void 0 : void 0) !== null) {
if (req.headers && req.headers.cookie !== null) {
rawCookies = req.headers.cookie;
}

Expand Down
Loading

0 comments on commit e2a1a1e

Please sign in to comment.