From 6e7b505ea762e40ca9a1c30949d022bf340ac297 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 24 Feb 2017 12:55:07 -0500 Subject: [PATCH] more linting --- public/src/client/flags/list.js | 4 +- src/controllers/mods.js | 16 ++++---- src/file.js | 2 +- src/flags.js | 67 +++++++++++++++++---------------- src/posts/delete.js | 1 - src/socket.io/flags.js | 9 ----- src/upgrade.js | 1 - src/user/admin.js | 2 - test/flags.js | 6 +-- 9 files changed, 48 insertions(+), 60 deletions(-) diff --git a/public/src/client/flags/list.js b/public/src/client/flags/list.js index 754dce8746..4c516eac38 100644 --- a/public/src/client/flags/list.js +++ b/public/src/client/flags/list.js @@ -16,7 +16,9 @@ define('forum/flags/list', ['components', 'Chart'], function (components, Chart) // Parse ajaxify data to set form values to reflect current filters for (var filter in ajaxify.data.filters) { - filtersEl.find('[name="' + filter + '"]').val(ajaxify.data.filters[filter]); + if (ajaxify.data.filters.hasOwnProperty(filter)) { + filtersEl.find('[name="' + filter + '"]').val(ajaxify.data.filters[filter]); + } } filtersEl.find('button').on('click', function () { diff --git a/src/controllers/mods.js b/src/controllers/mods.js index f55b852860..6365650323 100644 --- a/src/controllers/mods.js +++ b/src/controllers/mods.js @@ -42,16 +42,14 @@ modsController.flags.list = function (req, res, next) { if (!filters.cid) { // If mod and no cid filter, add filter for their modded categories filters.cid = res.locals.cids; - } else { + } else if (Array.isArray(filters.cid)) { // Remove cids they do not moderate - if (Array.isArray(filters.cid)) { - filters.cid = filters.cid.filter(function (cid) { - return res.locals.cids.indexOf(String(cid)) !== -1; - }); - } else if (res.locals.cids.indexOf(String(filters.cid)) === -1) { - filters.cid = res.locals.cids; - hasFilter = false; - } + filters.cid = filters.cid.filter(function (cid) { + return res.locals.cids.indexOf(String(cid)) !== -1; + }); + } else if (res.locals.cids.indexOf(String(filters.cid)) === -1) { + filters.cid = res.locals.cids; + hasFilter = false; } } diff --git a/src/file.js b/src/file.js index 572e2cf622..c48d24dc5e 100644 --- a/src/file.js +++ b/src/file.js @@ -92,7 +92,7 @@ file.allowedExtensions = function () { }; file.exists = function (path, callback) { - fs.stat(path, function (err, stat) { + fs.stat(path, function (err) { if (err) { if (err.code === 'ENOENT') { return callback(null, false); diff --git a/src/flags.js b/src/flags.js index 57dd90a8f6..33175d933f 100644 --- a/src/flags.js +++ b/src/flags.js @@ -1,7 +1,6 @@ 'use strict'; var async = require('async'); -var winston = require('winston'); var db = require('./database'); var user = require('./user'); var groups = require('./groups'); @@ -69,38 +68,40 @@ Flags.list = function (filters, uid, callback) { if (Object.keys(filters).length > 0) { for (var type in filters) { - switch (type) { - case 'type': - prepareSets('flags:byType:', filters[type]); - break; - - case 'state': - prepareSets('flags:byState:', filters[type]); - break; - - case 'reporterId': - prepareSets('flags:byReporter:', filters[type]); - break; - - case 'assignee': - prepareSets('flags:byAssignee:', filters[type]); - break; - - case 'targetUid': - prepareSets('flags:byTargetUid:', filters[type]); - break; - - case 'cid': - prepareSets('flags:byCid:', filters[type]); - break; - - case 'quick': - switch (filters.quick) { - case 'mine': - sets.push('flags:byAssignee:' + uid); + if (filters.hasOwnProperty(type)) { + switch (type) { + case 'type': + prepareSets('flags:byType:', filters[type]); + break; + + case 'state': + prepareSets('flags:byState:', filters[type]); + break; + + case 'reporterId': + prepareSets('flags:byReporter:', filters[type]); + break; + + case 'assignee': + prepareSets('flags:byAssignee:', filters[type]); + break; + + case 'targetUid': + prepareSets('flags:byTargetUid:', filters[type]); + break; + + case 'cid': + prepareSets('flags:byCid:', filters[type]); + break; + + case 'quick': + switch (filters.quick) { + case 'mine': + sets.push('flags:byAssignee:' + uid); + break; + } break; } - break; } } } @@ -341,7 +342,7 @@ Flags.create = function (type, id, uid, reason, timestamp, callback) { tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byPid:' + id, timestamp, flagId)); // by target pid } - async.parallel(tasks, function (err, data) { + async.parallel(tasks, function (err) { if (err) { return next(err); } @@ -479,7 +480,7 @@ Flags.update = function (flagId, uid, changeset, callback) { // Fire plugin hook tasks.push(async.apply(plugins.fireHook, 'action:flag.update', { flagId: flagId, changeset: changeset, uid: uid })); - async.parallel(tasks, function (err, data) { + async.parallel(tasks, function (err) { return next(err); }); }, diff --git a/src/posts/delete.js b/src/posts/delete.js index af281be698..a2874770af 100644 --- a/src/posts/delete.js +++ b/src/posts/delete.js @@ -8,7 +8,6 @@ var topics = require('../topics'); var user = require('../user'); var notifications = require('../notifications'); var plugins = require('../plugins'); -var flags = require('../flags'); module.exports = function (Posts) { Posts.delete = function (pid, uid, callback) { diff --git a/src/socket.io/flags.js b/src/socket.io/flags.js index d7964a1035..2cc2881832 100644 --- a/src/socket.io/flags.js +++ b/src/socket.io/flags.js @@ -1,17 +1,8 @@ 'use strict'; var async = require('async'); -var S = require('string'); var user = require('../user'); -var groups = require('../groups'); -var posts = require('../posts'); -var topics = require('../topics'); -var privileges = require('../privileges'); -var notifications = require('../notifications'); -var plugins = require('../plugins'); -var meta = require('../meta'); -var utils = require('../../public/src/utils'); var flags = require('../flags'); var SocketFlags = {}; diff --git a/src/upgrade.js b/src/upgrade.js index c37026ecd9..01c767315e 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -323,7 +323,6 @@ Upgrade.upgrade = function (callback) { var batch = require('./batch'); var posts = require('./posts'); var flags = require('./flags'); - var migrated = 0; batch.processSortedSet('posts:pid', function (ids, next) { posts.getPostsByPids(ids, 1, function (err, posts) { diff --git a/src/user/admin.js b/src/user/admin.js index cf3a2004db..28668cff80 100644 --- a/src/user/admin.js +++ b/src/user/admin.js @@ -3,10 +3,8 @@ var async = require('async'); var db = require('../database'); -var posts = require('../posts'); var plugins = require('../plugins'); var winston = require('winston'); -var flags = require('../flags'); module.exports = function (User) { User.logIP = function (uid, ip) { diff --git a/test/flags.js b/test/flags.js index 8623dbc269..0426541cd8 100644 --- a/test/flags.js +++ b/test/flags.js @@ -487,9 +487,9 @@ describe('Flags', function () { describe('(websockets)', function () { var SocketFlags = require('../src/socket.io/flags.js'); - var tid, - pid, - flag; + var tid; + var pid; + var flag; before(function (done) { Topics.post({