Skip to content

Commit

Permalink
Applied some suggested fixed by standardjs using npx standard src --f…
Browse files Browse the repository at this point in the history
…ix command, and then fixed resulting linting issues
  • Loading branch information
GhalyaJ committed Oct 18, 2023
1 parent e602bec commit f29b9a5
Show file tree
Hide file tree
Showing 305 changed files with 951 additions and 1,056 deletions.
30 changes: 16 additions & 14 deletions src/admin/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const { Translator } = require('../translator');

function filterDirectories(directories) {
return directories.map(
// get the relative path
// convert dir to use forward slashes
// get the relative path
// convert dir to use forward slashes
dir => dir.replace(/^.*(admin.*?).tpl$/, '$1').split(path.sep).join('/')
).filter(
// exclude .js files
// exclude partials
// only include subpaths
// exclude category.tpl, group.tpl, category-analytics.tpl
// exclude .js files
// exclude partials
// only include subpaths
// exclude category.tpl, group.tpl, category-analytics.tpl
dir => (
!dir.endsWith('.js') &&
!dir.includes('/partials/') &&
Expand Down Expand Up @@ -68,9 +68,9 @@ async function initFallback(namespace) {
translations += `\n${title}`;

return {
namespace: namespace,
translations: translations,
title: title,
namespace,
translations,
title,
};
}

Expand Down Expand Up @@ -104,19 +104,21 @@ async function buildNamespace(language, namespace) {
title = title.match(/admin\/(.+?)\/(.+?)$/);
title = `[[admin/menu:section-${
title[1] === 'development' ? 'advanced' : title[1]
}]]${title[2] ? (` > [[admin/menu:${
title[1]}/${title[2]}]]`) : ''}`;
}]]${title[2] ?
(` > [[admin/menu:${
title[1]}/${title[2]}]]`) :
''}`;

title = await translator.translate(title);
return {
namespace: namespace,
namespace,
translations: `${str}\n${title}`,
title: title,
title,
};
} catch (err) {
winston.error(err.stack);
return {
namespace: namespace,
namespace,
translations: '',
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/admin/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getLatestVersion(callback) {

request('https://api.github.com/repos/NodeBB/NodeBB/releases/latest', {
json: true,
headers: headers,
headers,
timeout: 2000,
}, (err, res, latestRelease) => {
if (err) {
Expand Down
12 changes: 6 additions & 6 deletions src/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ Analytics.init = async function () {
ttl: 0,
});

new cronJob('*/10 * * * * *', (async () => {
new cronJob('*/10 * * * * *', async () => {
publishLocalAnalytics();
if (runJobs) {
await sleep(2000);
await Analytics.writeData();
}
}), null, true);
}, null, true);

if (runJobs) {
pubsub.on('analytics:publish', (data) => {
Expand All @@ -59,7 +59,7 @@ Analytics.init = async function () {

function publishLocalAnalytics() {
pubsub.publish('analytics:publish', {
local: local,
local,
});
local = _.cloneDeep(empty);
}
Expand All @@ -78,7 +78,7 @@ function incrementProperties(obj1, obj2) {
Analytics.increment = function (keys, callback) {
keys = Array.isArray(keys) ? keys : [keys];

plugins.hooks.fire('action:analytics.increment', { keys: keys });
plugins.hooks.fire('action:analytics.increment', { keys });

keys.forEach((key) => {
local.counters[key] = local.counters[key] || 0;
Expand All @@ -104,7 +104,7 @@ Analytics.pageView = async function (payload) {
}

if (payload.ip) {
// Retrieve hash or calculate if not present
// Retrieve hash or calculate if not present
let hash = ipCache.get(payload.ip + secret);
if (!hash) {
hash = crypto.createHash('sha1').update(payload.ip + secret).digest('hex');
Expand Down Expand Up @@ -244,7 +244,7 @@ Analytics.getDailyStatsForSet = async function (set, day, numDays) {
day.setHours(0, 0, 0, 0);

while (numDays > 0) {
/* eslint-disable no-await-in-loop */
/* eslint-disable no-await-in-loop */
const dayData = await Analytics.getHourlyStatsForSet(
set,
day.getTime() - (1000 * 60 * 60 * 24 * (numDays - 1)),
Expand Down
2 changes: 1 addition & 1 deletion src/api/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ categoriesAPI.delete = async function (caller, data) {
uid: caller.uid,
ip: caller.ip,
cid: data.cid,
name: name,
name,
});
};

Expand Down
8 changes: 4 additions & 4 deletions src/api/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ flagsApi.create = async (caller, data) => {

await flags.validate({
uid: caller.uid,
type: type,
id: id,
type,
id,
});

const flagObj = await flags.create(type, id, caller.uid, reason);
Expand Down Expand Up @@ -61,7 +61,7 @@ flagsApi.appendNote = async (caller, data) => {
flags.getNotes(data.flagId),
flags.getHistory(data.flagId),
]);
return { notes: notes, history: history };
return { notes, history };
};

flagsApi.deleteNote = async (caller, data) => {
Expand All @@ -80,5 +80,5 @@ flagsApi.deleteNote = async (caller, data) => {
flags.getNotes(data.flagId),
flags.getHistory(data.flagId),
]);
return { notes: notes, history: history };
return { notes, history };
};
16 changes: 8 additions & 8 deletions src/api/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ groupsAPI.delete = async function (caller, data) {

await groups.destroy(groupName);
logGroupEvent(caller, 'group-delete', {
groupName: groupName,
groupName,
});
};

Expand Down Expand Up @@ -97,10 +97,10 @@ groupsAPI.join = async function (caller, data) {

const isSelf = parseInt(caller.uid, 10) === parseInt(data.uid, 10);
if (!meta.config.allowPrivateGroups && isSelf) {
// all groups are public!
// all groups are public!
await groups.join(groupName, data.uid);
logGroupEvent(caller, 'group-join', {
groupName: groupName,
groupName,
targetUid: data.uid,
});
return;
Expand All @@ -113,13 +113,13 @@ groupsAPI.join = async function (caller, data) {
if ((!groupData.private && isSelf) || isCallerAdmin || isCallerOwner) {
await groups.join(groupName, data.uid);
logGroupEvent(caller, 'group-join', {
groupName: groupName,
groupName,
targetUid: data.uid,
});
} else if (isSelf) {
await groups.requestMembership(groupName, caller.uid);
logGroupEvent(caller, 'group-request-membership', {
groupName: groupName,
groupName,
targetUid: data.uid,
});
}
Expand Down Expand Up @@ -184,7 +184,7 @@ groupsAPI.leave = async function (caller, data) {
await notifications.push(notification, uids);

logGroupEvent(caller, 'group-leave', {
groupName: groupName,
groupName,
targetUid: data.uid,
});
};
Expand All @@ -195,7 +195,7 @@ groupsAPI.grant = async (caller, data) => {

await groups.ownership.grant(data.uid, groupName);
logGroupEvent(caller, 'group-owner-grant', {
groupName: groupName,
groupName,
targetUid: data.uid,
});
};
Expand All @@ -206,7 +206,7 @@ groupsAPI.rescind = async (caller, data) => {

await groups.ownership.rescind(data.uid, groupName);
logGroupEvent(caller, 'group-owner-rescind', {
groupName: groupName,
groupName,
targetUid: data.uid,
});
};
Expand Down
8 changes: 4 additions & 4 deletions src/api/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ exports.buildReqObject = (req, payload) => {
body: payload || req.body,
session: req.session,
ip: req.ip,
host: host,
host,
protocol: encrypted ? 'https' : 'http',
secure: encrypted,
url: referer,
path: referer.slice(referer.indexOf(host) + host.length),
headers: headers,
headers,
};
};

Expand Down Expand Up @@ -80,7 +80,7 @@ async function logTopicAction(action, req, tid, title) {
type: `topic-${action}`,
uid: req.uid,
ip: req.ip,
tid: tid,
tid,
title: String(title),
});
}
Expand Down Expand Up @@ -119,7 +119,7 @@ exports.postCommand = async function (caller, command, eventName, notification,
filter:post.unbookmark
*/
const filteredData = await plugins.hooks.fire(`filter:post.${command}`, {
data: data,
data,
uid: caller.uid,
});
return await executeCommand(caller, command, eventName, notification, filteredData.data);
Expand Down
10 changes: 5 additions & 5 deletions src/api/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ postsAPI.edit = async function (caller, data) {
const selfPost = parseInt(caller.uid, 10) === parseInt(editResult.post.uid, 10);
if (!selfPost && editResult.post.changed) {
await events.log({
type: `post-edit`,
type: 'post-edit',
uid: caller.uid,
ip: caller.ip,
pid: editResult.post.pid,
Expand Down Expand Up @@ -214,7 +214,7 @@ async function isMainAndLastPost(pid) {
posts.getTopicFields(pid, ['postcount']),
]);
return {
isMain: isMain,
isMain,
isLast: topicData && topicData.postcount === 1,
};
}
Expand All @@ -240,7 +240,7 @@ postsAPI.move = async function (caller, data) {
posts.getPostField(data.pid, 'deleted'),
topics.getTopicField(data.tid, 'deleted'),
await events.log({
type: `post-move`,
type: 'post-move',
uid: caller.uid,
ip: caller.ip,
pid: data.pid,
Expand Down Expand Up @@ -306,9 +306,9 @@ postsAPI.getDiffs = async (caller, data) => {
timestamps.push(String(post.timestamp));

return {
timestamps: timestamps,
timestamps,
revisions: timestamps.map((timestamp, idx) => ({
timestamp: timestamp,
timestamp,
username: usernames[idx],
})),
// Only admins, global mods and moderator of that cid can delete a diff
Expand Down
10 changes: 5 additions & 5 deletions src/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ usersAPI.update = async function (caller, data) {
};

usersAPI.delete = async function (caller, { uid, password }) {
await processDeletion({ uid: uid, method: 'delete', password, caller });
await processDeletion({ uid, method: 'delete', password, caller });
};

usersAPI.deleteContent = async function (caller, { uid, password }) {
Expand Down Expand Up @@ -346,7 +346,7 @@ async function processDeletion({ uid, method, password, caller }) {

plugins.hooks.fire('action:user.delete', {
callerUid: caller.uid,
uid: uid,
uid,
ip: caller.ip,
user: userData,
});
Expand Down Expand Up @@ -398,7 +398,7 @@ usersAPI.search = async function (caller, data) {
searchBy: data.searchBy || 'username',
page: data.page || 1,
sortBy: data.sortBy || 'lastonline',
filters: filters,
filters,
});
};

Expand All @@ -425,7 +425,7 @@ usersAPI.changePicture = async (caller, data) => {
} else {
const returnData = await plugins.hooks.fire('filter:user.getPicture', {
uid: caller.uid,
type: type,
type,
picture: undefined,
});
picture = returnData && returnData.picture;
Expand All @@ -438,7 +438,7 @@ usersAPI.changePicture = async (caller, data) => {

await user.updateProfile(caller.uid, {
uid: data.uid,
picture: picture,
picture,
'icon:bgColor': data.bgColor,
}, ['picture', 'icon:bgColor']);
};
Expand Down
3 changes: 1 addition & 2 deletions src/batch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

'use strict';

const util = require('util');
Expand Down Expand Up @@ -40,7 +39,7 @@ exports.processSortedSet = async function (setKey, process, options) {
}

while (true) {
/* eslint-disable no-await-in-loop */
/* eslint-disable no-await-in-loop */
const ids = await db[`getSortedSetRange${options.withScores ? 'WithScores' : ''}`](setKey, start, stop);
if (!ids.length || options.doneIf(start, stop, ids)) {
return;
Expand Down
Loading

0 comments on commit f29b9a5

Please sign in to comment.