fix(style): requiring parens in block bodies

v1.18.x
Julian Lam 6 years ago
parent 0921230976
commit 29f96b199c

@ -43,7 +43,7 @@
}],
"no-else-return": [ "error", { "allowElseIf": true } ],
"operator-linebreak": [ "error", "after" ],
"arrow-parens": ["error", "as-needed"],
"arrow-parens": ["error", "as-needed", { "requireForBlockBody": true }],
// ES6
"prefer-rest-params": "off",

@ -146,7 +146,7 @@ Categories.getCategories = async function (cids, uid) {
Categories.getTagWhitelist = async function (cids) {
const cachedData = {};
const nonCachedCids = cids.filter(cid => {
const nonCachedCids = cids.filter((cid) => {
const data = cache.get('cid:' + cid + ':tag:whitelist');
const isInCache = data !== undefined;
if (isInCache) {

@ -157,7 +157,7 @@ module.exports = function (Categories) {
const bulkRemove = [];
const bulkAdd = [];
postData.forEach(post => {
postData.forEach((post) => {
bulkRemove.push(['cid:' + oldCid + ':uid:' + post.uid + ':pids', post.pid]);
bulkRemove.push(['cid:' + oldCid + ':uid:' + post.uid + ':pids:votes', post.pid]);
bulkAdd.push(['cid:' + cid + ':uid:' + post.uid + ':pids', post.timestamp, post.pid]);

@ -202,7 +202,7 @@ authenticationController.registerComplete = function (req, res, next) {
delete payload.uid;
delete payload.returnTo;
Object.keys(payload).forEach(prop => {
Object.keys(payload).forEach((prop) => {
if (typeof payload[prop] === 'boolean') {
payload[prop] = payload[prop] ? 1 : 0;
}

@ -238,7 +238,7 @@ async function addTags(topicData, req, res) {
async function addOGImageTags(res, topicData, postAtIndex) {
const uploads = postAtIndex ? await posts.uploads.listWithSizes(postAtIndex.pid) : [];
const images = uploads.map(upload => {
const images = uploads.map((upload) => {
upload.name = nconf.get('url') + nconf.get('upload_url') + '/files/' + upload.name;
return upload;
});

@ -12,7 +12,7 @@ if (!databaseName) {
var primaryDB = require('./' + databaseName);
primaryDB.parseIntFields = function (data, intFields, requestedFields) {
intFields.forEach(field => {
intFields.forEach((field) => {
if (!requestedFields.length || requestedFields.includes(field)) {
data[field] = parseInt(data[field], 10) || 0;
}

@ -86,7 +86,7 @@ module.exports = function (module) {
const item = cachedData[key] || {};
const result = {};
fields.forEach(field => {
fields.forEach((field) => {
result[field] = item[field] !== undefined ? item[field] : null;
});
return result;

@ -117,7 +117,7 @@ module.exports = function (module) {
const item = cachedData[key] || {};
const result = {};
fields.forEach(field => {
fields.forEach((field) => {
result[field] = item[field] !== undefined ? item[field] : null;
});
return result;

@ -32,7 +32,7 @@ module.exports = function (module) {
return [];
}
const batch = module.client.batch();
key.forEach(key => {
key.forEach((key) => {
batch[method]([key, start, stop, 'WITHSCORES']);
});
let data = await helpers.execBatch(batch);

@ -6,7 +6,7 @@ var db = require('../database');
var user = require('../user');
module.exports = function (Messaging) {
Messaging.sendMessage = async data => {
Messaging.sendMessage = async (data) => {
await Messaging.checkContent(data.content);
const inRoom = await Messaging.isUserInRoom(data.uid, data.roomId);
if (!inRoom) {
@ -16,7 +16,7 @@ module.exports = function (Messaging) {
return await Messaging.addMessage(data);
};
Messaging.checkContent = async content => {
Messaging.checkContent = async (content) => {
if (!content) {
throw new Error('[[error:invalid-chat-message]]');
}
@ -32,7 +32,7 @@ module.exports = function (Messaging) {
}
};
Messaging.addMessage = async data => {
Messaging.addMessage = async (data) => {
const mid = await db.incrObjectField('global', 'nextMid');
const timestamp = data.timestamp || new Date().getTime();
let message = {

@ -77,7 +77,7 @@ module.exports = function (Messaging) {
message.system = !!message.system;
});
messages = await Promise.all(messages.map(async message => {
messages = await Promise.all(messages.map(async (message) => {
if (message.system) {
return message;
}

@ -20,7 +20,7 @@ require('./unread')(Messaging);
require('./notifications')(Messaging);
Messaging.getMessages = async params => {
Messaging.getMessages = async (params) => {
const isNew = params.isNew || false;
const start = params.hasOwnProperty('start') ? params.start : 0;
const stop = parseInt(start, 10) + ((params.count || 50) - 1);
@ -98,7 +98,7 @@ Messaging.getRecentChats = async (callerUid, uid, start, stop) => {
const results = await utils.promiseParallel({
roomData: Messaging.getRoomsData(roomIds),
unread: db.isSortedSetMembers('uid:' + uid + ':chat:rooms:unread', roomIds),
users: Promise.all(roomIds.map(async roomId => {
users: Promise.all(roomIds.map(async (roomId) => {
let uids = await db.getSortedSetRevRange('chat:room:' + roomId + ':uids', 0, 9);
uids = uids.filter(function (value) {
return value && parseInt(value, 10) !== parseInt(uid, 10);

@ -9,7 +9,7 @@ var privileges = require('../privileges');
var meta = require('../meta');
module.exports = function (Messaging) {
Messaging.getRoomData = async roomId => {
Messaging.getRoomData = async (roomId) => {
const data = await db.getObject('chat:room:' + roomId);
if (!data) {
throw new Error('[[error:no-chat-room]]');
@ -19,7 +19,7 @@ module.exports = function (Messaging) {
return data;
};
Messaging.getRoomsData = async roomIds => {
Messaging.getRoomsData = async (roomIds) => {
const roomData = await db.getObjects(roomIds.map(function (roomId) {
return 'chat:room:' + roomId;
}));

@ -4,7 +4,7 @@ var db = require('../database');
var sockets = require('../socket.io');
module.exports = function (Messaging) {
Messaging.getUnreadCount = async uid => {
Messaging.getUnreadCount = async (uid) => {
if (parseInt(uid, 10) <= 0) {
return 0;
}
@ -12,7 +12,7 @@ module.exports = function (Messaging) {
return await db.sortedSetCard('uid:' + uid + ':chat:rooms:unread');
};
Messaging.pushUnreadCount = async uid => {
Messaging.pushUnreadCount = async (uid) => {
if (parseInt(uid, 10) <= 0) {
return;
}

@ -83,7 +83,7 @@ async function getTemplateDirs(activePlugins) {
}
async function getTemplateFiles(dirs) {
const buckets = await Promise.all(dirs.map(async dir => {
const buckets = await Promise.all(dirs.map(async (dir) => {
let files = await file.walk(dir);
files = files.filter(function (path) {
return path.endsWith('.tpl');
@ -132,7 +132,7 @@ async function compile() {
files = await getTemplateDirs(files);
files = await getTemplateFiles(files);
await Promise.all(Object.keys(files).map(async name => {
await Promise.all(Object.keys(files).map(async (name) => {
const filePath = files[name];
let imported = await fsReadFile(filePath, 'utf8');
imported = await processImports(files, name, imported);

@ -30,7 +30,7 @@ Themes.get = async () => {
let themes = await getThemes(themePath);
themes = _.flatten(themes).filter(Boolean);
themes = await Promise.all(themes.map(async theme => {
themes = await Promise.all(themes.map(async (theme) => {
const config = path.join(themePath, theme, 'theme.json');
try {
const file = await fsReadfile(config, 'utf8');
@ -61,7 +61,7 @@ Themes.get = async () => {
async function getThemes(themePath) {
let dirs = await fsReaddir(themePath);
dirs = dirs.filter(dir => themeNamePattern.test(dir) || dir.startsWith('@'));
return await Promise.all(dirs.map(async dir => {
return await Promise.all(dirs.map(async (dir) => {
try {
const dirpath = path.join(themePath, dir);
const stat = await fsStat(dirpath);
@ -85,7 +85,7 @@ async function getThemes(themePath) {
}));
}
Themes.set = async data => {
Themes.set = async (data) => {
const themeData = {
'theme:type': data.type,
'theme:id': data.id,

@ -238,7 +238,7 @@ module.exports = function (middleware) {
function (data, next) {
async.parallel({
scripts: async.apply(plugins.fireHook, 'filter:scripts.get', []),
timeagoLocale: next => {
timeagoLocale: (next) => {
async.waterfall([
async.apply(languages.listCodes),
(languageCodes, next) => {

@ -157,7 +157,7 @@ module.exports = function (Plugins) {
next();
}, 5000);
const onError = err => {
const onError = (err) => {
winston.error('[plugins] Error executing \'' + hook + '\' in plugin \'' + hookObj.id + '\'');
winston.error(err);
clearTimeout(timeoutId);

@ -88,7 +88,7 @@ module.exports = function (Plugins) {
const fields = _.uniq(_.flatMap(targets, target => map[target] || []));
// clear old data before build
fields.forEach(field => {
fields.forEach((field) => {
switch (field) {
case 'clientScripts':
case 'acpScripts':

@ -108,7 +108,7 @@ module.exports = function (Posts) {
]);
};
Posts.uploads.saveSize = async filePaths => {
Posts.uploads.saveSize = async (filePaths) => {
await Promise.all(filePaths.map(async function (fileName) {
try {
const size = await image.size(path.join(pathPrefix, fileName));

@ -207,7 +207,7 @@ module.exports = function (Posts) {
const bulkAdd = [];
const bulkRemove = [];
const postsByUser = {};
mainPosts.forEach(post => {
mainPosts.forEach((post) => {
bulkRemove.push(['cid:' + post.cid + ':uid:' + post.uid + ':tids', post.tid]);
bulkRemove.push(['uid:' + post.uid + ':topics', post.tid]);

@ -22,7 +22,7 @@ function setupWinston() {
formats.push(winston.format.timestamp());
formats.push(winston.format.json());
} else {
const timestampFormat = winston.format(info => {
const timestampFormat = winston.format((info) => {
var dateString = new Date().toISOString() + ' [' + nconf.get('port') + '/' + global.process.pid + ']';
info.level = dateString + ' - ' + info.level;
return info;

@ -148,8 +148,8 @@ helpers.giveOrRescind = async function (method, privileges, cids, groupNames) {
cids = Array.isArray(cids) ? cids : [cids];
for (const groupName of groupNames) {
const groupKeys = [];
cids.forEach(cid => {
privileges.forEach(privilege => {
cids.forEach((cid) => {
privileges.forEach((privilege) => {
groupKeys.push('cid:' + cid + ':privileges:groups:' + privilege);
});
});

@ -166,7 +166,7 @@ SocketModules.chats.getUsersInRoom = function (socket, data, callback) {
return callback(err);
}
payload.users = payload.users.map(user => {
payload.users = payload.users.map((user) => {
user.canKick = (parseInt(user.uid, 10) !== parseInt(socket.uid, 10)) && payload.isOwner;
return user;
});

@ -90,7 +90,7 @@ module.exports = function (Topics) {
return tids.map(() => ({ following: false, ignoring: false }));
}
const keys = [];
tids.forEach(tid => {
tids.forEach((tid) => {
keys.push('tid:' + tid + ':followers', 'tid:' + tid + ':ignorers');
});

@ -98,7 +98,7 @@ module.exports = function (User) {
property = 'uid';
}
if (!Array.isArray(set) || !set.length || !set.every(item => {
if (!Array.isArray(set) || !set.length || !set.every((item) => {
if (!item) {
return false;
}

Loading…
Cancel
Save