From ba7c0c01af364ccd49f46c7d669c2a4e26e90ea6 Mon Sep 17 00:00:00 2001 From: Jeroen van Warmerdam Date: Fri, 28 Nov 2014 15:11:57 +0100 Subject: [PATCH 1/4] Some JSHint fixes; --- app.js | 1 - controllers/admin.js | 6 +----- controllers/auth.js | 3 +-- controllers/discussion.js | 1 - controllers/group.js | 1 - controllers/index.js | 4 ++-- controllers/issue.js | 12 ++++++------ controllers/moderation.js | 1 - controllers/script.js | 15 +++------------ controllers/scriptStorage.js | 8 +++----- controllers/user.js | 33 ++++++++++++--------------------- libs/collectiveRating.js | 1 - libs/flag.js | 4 ++-- libs/githubClient.js | 4 ++-- libs/modelParser.js | 5 ++--- libs/modifySessions.js | 2 +- libs/passportVerify.js | 2 +- libs/remove.js | 12 ++++++------ libs/repoManager.js | 6 +----- libs/templateHelpers.js | 6 +++--- routes.js | 2 -- 21 files changed, 46 insertions(+), 83 deletions(-) diff --git a/app.js b/app.js index 743dc314e..6486effa2 100755 --- a/app.js +++ b/app.js @@ -26,7 +26,6 @@ var passport = require('passport'); var app = express(); -var statusCodePage = require('./libs/templateHelpers').statusCodePage; var modifySessions = require('./libs/modifySessions'); var settings = require('./models/settings.json'); diff --git a/controllers/admin.js b/controllers/admin.js index 06113073c..ac66fa87c 100644 --- a/controllers/admin.js +++ b/controllers/admin.js @@ -24,7 +24,6 @@ var userRoles = require('../models/userRoles.json'); var strategies = require('./strategies.json'); var loadPassport = require('../libs/passportLoader').loadPassport; var strategyInstances = require('../libs/passportLoader').strategyInstances; -var scriptStorage = require('./scriptStorage'); var modelParser = require('../libs/modelParser'); var helpers = require('../libs/helpers'); var statusCodePage = require('../libs/templateHelpers').statusCodePage; @@ -66,7 +65,6 @@ exports.userAdmin = function (aReq, aRes, aNext) { // You can only see users with a role less than yours User.find({ role: { $gt: thisUser.role } }, function (aErr, aUsers) { // TODO: STYLEGUIDE.md conformance needed here - var i = 0; options.users = []; aUsers.forEach(function (aUser) { @@ -168,7 +166,6 @@ exports.adminUserUpdate = function (aReq, aRes, aNext) { // var options = {}; - var tasks = []; // Session authedUser = options.authedUser = modelParser.parseUser(authedUser); @@ -184,7 +181,7 @@ exports.adminUserUpdate = function (aReq, aRes, aNext) { // User var user = options.user = modelParser.parseUser(aUserData); - options.isYou = authedUser && user && authedUser._id == user._id; + options.isYou = authedUser && user && authedUser._id === user._id; //--- @@ -428,7 +425,6 @@ exports.authAsUser = function (aReq, aRes, aNext) { // var options = {}; - var tasks = []; // Session authedUser = options.authedUser = modelParser.parseUser(authedUser); diff --git a/controllers/auth.js b/controllers/auth.js index 79b95f892..bc1e14e35 100644 --- a/controllers/auth.js +++ b/controllers/auth.js @@ -12,7 +12,6 @@ var loadPassport = require('../libs/passportLoader').loadPassport; var strategyInstances = require('../libs/passportLoader').strategyInstances; var Strategy = require('../models/strategy.js').Strategy; var User = require('../models/user').User; -var userRoles = require('../models/userRoles.json'); var verifyPassport = require('../libs/passportVerify').verify; var cleanFilename = require('../libs/helpers').cleanFilename; var addSession = require('../libs/modifySessions').add; @@ -122,7 +121,7 @@ exports.callback = function (aReq, aRes, aNext) { if (openIdStrategies[strategy]) { strategyInstance._verify = function (aId, aDone) { verifyPassport(aId, strategy, username, aReq.session.user, aDone); - } + }; } else { strategyInstance._verify = function (aToken, aRefreshOrSecretToken, aProfile, aDone) { diff --git a/controllers/discussion.js b/controllers/discussion.js index 797d01215..4ba2bf39b 100644 --- a/controllers/discussion.js +++ b/controllers/discussion.js @@ -452,7 +452,6 @@ exports.createComment = function (aReq, aRes, aNext) { var topic = aReq.params.topic; var user = aReq.session.user; var content = aReq.body['comment-content']; - var commentId = aReq.body['comment-id']; // for editing if (!user) { return aNext(); } diff --git a/controllers/group.js b/controllers/group.js index 16b82950e..7192c3b34 100644 --- a/controllers/group.js +++ b/controllers/group.js @@ -209,7 +209,6 @@ exports.list = function (aReq, aRes) { var setupGroupSidePanel = function (aOptions) { // Shortcuts - var group = aOptions.group; var authedUser = aOptions.authedUser; // Mod diff --git a/controllers/index.js b/controllers/index.js index 204f7932d..d26a02501 100644 --- a/controllers/index.js +++ b/controllers/index.js @@ -145,7 +145,7 @@ exports.home = function (aReq, aRes) { pageMetadata(options, ['Flagged Scripts', 'Moderation']); } } - }; + } function render() { aRes.render('pages/scriptListPage', options); } function asyncComplete() { preRender(); render(); } async.parallel(tasks, asyncComplete); @@ -217,7 +217,7 @@ exports.register = function (aReq, aRes) { var githubStrategy = _.findWhere(options.strategies, { strat: 'github' }); if (githubStrategy) githubStrategy.selected = true; - }; + } function render() { aRes.render('pages/loginPage', options); } function asyncComplete() { preRender(); render(); } async.parallel(tasks, asyncComplete); diff --git a/controllers/issue.js b/controllers/issue.js index 75d332f1b..c2ddeff86 100644 --- a/controllers/issue.js +++ b/controllers/issue.js @@ -53,7 +53,7 @@ exports.list = function (aReq, aRes, aNext) { // Script var script = options.script = modelParser.parseScript(scriptData); - options.isOwner = authedUser && authedUser._id == script._authorId; + options.isOwner = authedUser && authedUser._id === script._authorId; // Category var category = {}; @@ -167,7 +167,7 @@ exports.view = function (aReq, aRes, aNext) { // Script var script = options.script = modelParser.parseScript(aScriptData); - options.isOwner = authedUser && authedUser._id == script._authorId; + options.isOwner = authedUser && authedUser._id === script._authorId; // Category var category = {}; @@ -185,8 +185,8 @@ exports.view = function (aReq, aRes, aNext) { // Discussion var discussion = options.discussion = modelParser.parseDiscussion(aDiscussionData); modelParser.parseIssue(discussion); - options.canClose = authedUser && (authedUser._id == script._authorId || authedUser._id == discussion._authorId); - options.canOpen = authedUser && authedUser._id == script._authorId; + options.canClose = authedUser && (authedUser._id === script._authorId || authedUser._id === discussion._authorId); + options.canOpen = authedUser && authedUser._id === script._authorId; // commentListQuery var commentListQuery = Comment.find(); @@ -255,7 +255,7 @@ exports.open = function (aReq, aRes, aNext) { function preRender() { // Page metadata pageMetadata(options, ['New Issue', script.name]); - }; + } function render() { aRes.render('pages/scriptNewIssuePage', options); } function asyncComplete() { preRender(); render(); } @@ -273,7 +273,7 @@ exports.open = function (aReq, aRes, aNext) { // Script var script = options.script = modelParser.parseScript(aScriptData); - options.isOwner = authedUser && authedUser._id == script._authorId; + options.isOwner = authedUser && authedUser._id === script._authorId; // Category var category = {}; diff --git a/controllers/moderation.js b/controllers/moderation.js index 474130460..f6d5283db 100644 --- a/controllers/moderation.js +++ b/controllers/moderation.js @@ -25,7 +25,6 @@ exports.removedItemPage = function (aReq, aRes, aNext) { // var options = {}; - var tasks = []; // Session authedUser = options.authedUser = modelParser.parseUser(authedUser); diff --git a/controllers/script.js b/controllers/script.js index f9a9609d2..4abf743d2 100644 --- a/controllers/script.js +++ b/controllers/script.js @@ -6,8 +6,6 @@ var isDev = require('../libs/debug').isDev; var isDbg = require('../libs/debug').isDbg; // -var fs = require('fs'); -var formidable = require('formidable'); var async = require('async'); var _ = require('underscore'); var sanitizeHtml = require('sanitize-html'); @@ -266,7 +264,6 @@ var getScriptPageTasks = function (aOptions) { var setupScriptSidePanel = function (aOptions) { // Shortcuts - var script = aOptions.script; var authedUser = aOptions.authedUser; // User @@ -292,8 +289,6 @@ exports.view = function (aReq, aRes, aNext) { var authedUser = aReq.session.user; var installNameSlug = scriptStorage.getInstallName(aReq); - var scriptAuthor = aReq.params.username; - var scriptNameSlug = aReq.params.scriptname; var isLib = aReq.params.isLib; Script.findOne({ @@ -322,7 +317,7 @@ exports.view = function (aReq, aRes, aNext) { // Script var script = options.script = modelParser.parseScript(aScriptData); - options.isOwner = authedUser && authedUser._id == script._authorId; + options.isOwner = authedUser && authedUser._id === script._authorId; modelParser.renderScript(script); script.installNameSlug = installNameSlug; script.scriptPermalinkInstallPageUrl = 'http://' + aReq.get('host') + script.scriptInstallPageUrl; @@ -357,8 +352,6 @@ exports.edit = function (aReq, aRes, aNext) { aReq.params.username = authedUser.name.toLowerCase(); var installNameSlug = scriptStorage.getInstallName(aReq); - var scriptAuthor = aReq.params.username; - var scriptNameSlug = aReq.params.scriptname; var isLib = aReq.params.isLib; Script.findOne({ @@ -389,7 +382,7 @@ exports.edit = function (aReq, aRes, aNext) { // Page metadata var script = options.script = modelParser.parseScript(aScriptData); - options.isOwner = authedUser && authedUser._id == script._authorId; + options.isOwner = authedUser && authedUser._id === script._authorId; pageMetadata(options, ['Edit', script.name, (script.isLib ? 'Libraries' : 'Scripts')], script.name); @@ -400,8 +393,6 @@ exports.edit = function (aReq, aRes, aNext) { options.searchBarPlaceholder = modelQuery.scriptListQueryDefaults.searchBarPlaceholder; options.searchBarFormAction = modelQuery.scriptListQueryDefaults.searchBarFormAction; - var baseUrl = script && script.isLib ? '/libs/' : '/scripts/'; - if (aReq.body.remove) { // POST scriptStorage.deleteScript(aScriptData.installName, function () { @@ -486,7 +477,7 @@ exports.vote = function (aReq, aRes, aNext) { if (!aScript.rating) { aScript.rating = 0; } if (!aScript.votes) { aScript.votes = 0; } - if (user._id == aScript._authorId || (!aVoteModel && unvote)) { + if (user._id === aScript._authorId || (!aVoteModel && unvote)) { return aRes.redirect(url); } else if (!aVoteModel) { aVoteModel = new Vote({ diff --git a/controllers/scriptStorage.js b/controllers/scriptStorage.js index ac7706636..23683d3a7 100644 --- a/controllers/scriptStorage.js +++ b/controllers/scriptStorage.js @@ -61,7 +61,6 @@ exports.getSource = function (aReq, aCallback) { exports.sendScript = function (aReq, aRes, aNext) { var accept = aReq.headers.accept; - var installName = null; if (0 !== aReq.url.indexOf('/libs/') && accept === 'text/x-userscript-meta') { return exports.sendMeta(aReq, aRes, aNext); @@ -234,7 +233,6 @@ exports.getMeta = function (aChunks, aCallback) { // get the user script header. var str = ''; var i = 0; - var len = aChunks.length; var header = null; for (; i < aChunks.length; ++i) { @@ -270,7 +268,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) { if (!scriptName) { return aCallback(null); } if (!isLibrary && aMeta.oujs && aMeta.oujs.author - && aMeta.oujs.author != aUser.name && aMeta.oujs.collaborator) { + && aMeta.oujs.author !== aUser.name && aMeta.oujs.collaborator) { collaborators = aMeta.oujs.collaborator; if ((typeof collaborators === 'string' && collaborators === aUser.name) @@ -329,8 +327,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) { } else { // Script already exists. if (!aScript.isLib) { - if (collaborators && (aScript.meta.oujs && aScript.meta.oujs.author != aMeta.oujs.author - || (aScript.meta.oujs && JSON.stringify(aScript.meta.oujs.collaborator) != + if (collaborators && (aScript.meta.oujs && aScript.meta.oujs.author !== aMeta.oujs.author + || (aScript.meta.oujs && JSON.stringify(aScript.meta.oujs.collaborator) !== JSON.stringify(aMeta.oujs.collaborator)))) { return aCallback(null); } diff --git a/controllers/user.js b/controllers/user.js index eca0ec872..048880346 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -13,7 +13,6 @@ var _ = require('underscore'); var util = require('util'); var Comment = require('../models/comment').Comment; -var Flag = require('../models/flag').Flag; var Script = require('../models/script').Script; var Strategy = require('../models/strategy').Strategy; var User = require('../models/user').User; @@ -97,7 +96,6 @@ var getUserPageTasks = function (aOptions) { // Shortcuts var user = aOptions.user; - var authedUser = aOptions.authedUser; //--- Tasks @@ -218,7 +216,7 @@ exports.userListPage = function (aReq, aRes, aNext) { } } function render() { aRes.render('pages/userListPage', options); } - function asyncComplete(err) { if (err) { return aNext(); } else { preRender(); render(); } }; + function asyncComplete(err) { if (err) { return aNext(); } else { preRender(); render(); } } async.parallel(tasks, asyncComplete); }; @@ -245,7 +243,7 @@ exports.view = function (aReq, aRes, aNext) { // User var user = options.user = modelParser.parseUser(aUserData); user.aboutRendered = renderMd(user.about); - options.isYou = authedUser && user && authedUser._id == user._id; + options.isYou = authedUser && user && authedUser._id === user._id; // Page metadata pageMetadata(options, [user.name, 'Users']); @@ -263,9 +261,6 @@ exports.view = function (aReq, aRes, aNext) { // scriptListQuery: Defaults modelQuery.applyScriptListQueryDefaults(scriptListQuery, options, aReq); - // scriptListQuery: Pagination - var pagination = options.pagination; // is set in modelQuery.apply___ListQueryDefaults - //--- Tasks // UserPage tasks @@ -303,7 +298,7 @@ exports.userCommentListPage = function (aReq, aRes, aNext) { // User var user = options.user = modelParser.parseUser(aUserData); - options.isYou = authedUser && user && authedUser._id == user._id; + options.isYou = authedUser && user && authedUser._id === user._id; // Page metadata pageMetadata(options, [user.name, 'Users']); @@ -387,7 +382,7 @@ exports.userScriptListPage = function (aReq, aRes, aNext) { // User var user = options.user = modelParser.parseUser(aUserData); - options.isYou = authedUser && user && authedUser._id == user._id; + options.isYou = authedUser && user && authedUser._id === user._id; // Page metadata pageMetadata(options, [user.name, 'Users']); @@ -463,8 +458,6 @@ exports.userEditProfilePage = function (aReq, aRes, aNext) { if (!authedUser) { return aRes.redirect('/login'); } - var username = aReq.params.username; - User.findOne({ _id: authedUser._id }, function (aErr, aUserData) { @@ -481,7 +474,7 @@ exports.userEditProfilePage = function (aReq, aRes, aNext) { // User var user = options.user = modelParser.parseUser(aUserData); - options.isYou = authedUser && user && authedUser._id == user._id; + options.isYou = authedUser && user && authedUser._id === user._id; // Page metadata pageMetadata(options, [user.name, 'Users']); @@ -541,7 +534,7 @@ exports.userEditPreferencesPage = function (aReq, aRes, aNext) { // User var user = options.user = modelParser.parseUser(aUserData); - options.isYou = authedUser && user && authedUser._id == user._id; + options.isYou = authedUser && user && authedUser._id === user._id; // Page metadata pageMetadata(options, [user.name, 'Users']); @@ -870,7 +863,6 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) { // var options = {}; - var tasks = []; // Session authedUser = options.authedUser = modelParser.parseUser(authedUser); @@ -1015,7 +1007,7 @@ exports.userGitHubRepoPage = function (aReq, aRes, aNext) { options.repo = aRepo; options.repoAsEncoded = { default_branch: encodeURI(options.repo.default_branch) - } + }; github.gitdata.getJavascriptBlobs({ user: encodeURIComponent(aRepo.owner.login), @@ -1039,7 +1031,7 @@ exports.userGitHubRepoPage = function (aReq, aRes, aNext) { aCallback(null); }, - ], aCallback) + ], aCallback); }); //--- @@ -1108,7 +1100,6 @@ exports.userManageGitHubPage = function (aReq, aRes, aNext) { pageMetadata(options, ['Manage', 'GitHub']); // - var TOO_MANY_SCRIPTS = 'GitHub user has too many scripts to batch import.'; tasks.push(function (aCallback) { var githubUserName = aReq.query.user || authedUser.ghUsername; @@ -1127,7 +1118,7 @@ exports.userManageGitHubPage = function (aReq, aRes, aNext) { }, function (aGithubUser, aCallback) { options.githubUser = aGithubUser; - console.log(githubUser); + console.log(aGithubUser); User.findOne({ _id: authedUser._id }, aCallback); @@ -1164,7 +1155,7 @@ exports.userManageGitHubPage = function (aReq, aRes, aNext) { console.log(aReq.body); _.each(aReq.body, function (aRepo, aReponame) { // Load all scripts in the repo - if (typeof aRepo === 'string' && reponame.substr(-4) === '_all') { + if (typeof aRepo === 'string' && aReponame.substr(-4) === '_all') { aReponame = aRepo; aRepo = aRepos[aReponame]; @@ -1401,7 +1392,7 @@ function getExistingScript(aReq, aOptions, aAuthedUser, aCallback) { aOptions.source = Buffer.concat(bufs).toString('utf8'); aOptions.original = aScript.installName; aOptions.url = aReq.url; - aOptions.owner = aAuthedUser && (aScript._authorId == aAuthedUser._id + aOptions.owner = aAuthedUser && (aScript._authorId === aAuthedUser._id || collaborators.indexOf(aAuthedUser.name) > -1); aOptions.username = aAuthedUser ? aAuthedUser.name : null; aOptions.isLib = aScript.isLib; @@ -1459,7 +1450,7 @@ exports.editScript = function (aReq, aRes, aNext) { // Script var script = options.script = modelParser.parseScript(aScriptData); - options.isOwner = authedUser && authedUser._id == script._authorId; + options.isOwner = authedUser && authedUser._id === script._authorId; modelParser.renderScript(script); script.installNameSlug = installNameSlug; script.scriptPermalinkInstallPageUrl = 'http://' + aReq.get('host') + script.scriptInstallPageUrl; diff --git a/libs/collectiveRating.js b/libs/collectiveRating.js index 9732af4ec..dddb11ca0 100644 --- a/libs/collectiveRating.js +++ b/libs/collectiveRating.js @@ -46,7 +46,6 @@ exports.getRating = getRating; // expiring cache (either memory or DB based) to // speed up voting and flagging exports.getKarma = function (aUser, aMaxKarma, aCallback) { - var ratings = []; var karma = 0; Script.find({ _authorId: aUser._id }, 'rating', function (aErr, aScripts) { if (aErr) { return aCallback(karma); } diff --git a/libs/flag.js b/libs/flag.js index 22139fd44..740b974f6 100644 --- a/libs/flag.js +++ b/libs/flag.js @@ -26,7 +26,7 @@ function flaggable(aModel, aContent, aUser, aCallback) { // to police the site administration if (aModel.modelName === 'User') { return getFlag(aModel, aContent, aUser, function (aFlag) { - aCallback(aContent._id != aUser._id && aContent.role > 2, aContent, aFlag); + aCallback(aContent._id !== aUser._id && aContent.role > 2, aContent, aFlag); }); } @@ -35,7 +35,7 @@ function flaggable(aModel, aContent, aUser, aCallback) { if (!aAuthor) { return aCallback(false); } // You can't flag your own content - if (aAuthor._id == aUser._id) { return aCallback(false); } + if (aAuthor._id === aUser._id) { return aCallback(false); } // Content belonging to an admin or above cannot be flagged if (aAuthor.role < 3) { return aCallback(aAuthor.role > 2, aAuthor); } diff --git a/libs/githubClient.js b/libs/githubClient.js index 586bd3031..bd496ff28 100644 --- a/libs/githubClient.js +++ b/libs/githubClient.js @@ -47,7 +47,7 @@ var githubGitDataGetBlobAsUtf8 = function (aMsg, aCallback) { }, function (aBlob, aCallback) { var content = aBlob.content; - if (aBlob.encoding == 'base64') { + if (aBlob.encoding === 'base64') { var buf = new Buffer(content, 'base64'); content = buf.toString('utf8'); } @@ -69,7 +69,7 @@ var githubUserContentGetBlobAsUtf8 = function (aMsg, aCallback) { request.get(url, aCallback); }, function (aResponse, aBody, aCallback) { - if (aResponse.statusCode != 200) + if (aResponse.statusCode !== 200) return aCallback(util.format('Status Code %s', aResponse.statusCode)); aCallback(null, aBody); diff --git a/libs/modelParser.js b/libs/modelParser.js index 3d3706ac9..abd4dcd1f 100644 --- a/libs/modelParser.js +++ b/libs/modelParser.js @@ -16,7 +16,6 @@ var Script = require('../models/script').Script; var userRoles = require('../models/userRoles.json'); var renderMd = require('../libs/markdown').renderMd; -var helpers = require('../libs/helpers'); var getRating = require('../libs/collectiveRating').getRating; var cleanFilename = require('../libs/helpers').cleanFilename; @@ -328,7 +327,7 @@ var parseDiscussion = function (aDiscussionData) { var recentCommentors = []; if (discussion.author) recentCommentors.push(discussion.author); - if (discussion.lastCommentor != discussion.author) + if (discussion.lastCommentor !== discussion.author) recentCommentors.push(discussion.lastCommentor); recentCommentors = _.map(recentCommentors, function (aUsername) { return { @@ -396,7 +395,7 @@ var canUserPostTopicToCategory = function (aUser, aCategory) { return false; // Not logged in. // Check if this category requires a minimum role to post topics. - console.log(aCategory.roleReqToPostTopic, _.isNumber(aCategory.roleReqToPostTopic), aUser.role, aUser.role <= aCategory.roleReqToPostTopic) + console.log(aCategory.roleReqToPostTopic, _.isNumber(aCategory.roleReqToPostTopic), aUser.role, aUser.role <= aCategory.roleReqToPostTopic); if (_.isNumber(aCategory.roleReqToPostTopic)) { return aUser.role <= aCategory.roleReqToPostTopic; } else { diff --git a/libs/modifySessions.js b/libs/modifySessions.js index 054dee0e6..2dd6582b9 100644 --- a/libs/modifySessions.js +++ b/libs/modifySessions.js @@ -104,7 +104,7 @@ exports.destroy = function (aReq, aUser, aCallback) { } }; - if (!aUser || !aUser.sessionIds) { return aCb('No sessions', null); } + if (!aUser || !aUser.sessionIds) { return aCallback('No sessions', null); } async.each(aUser.sessionIds, function (aId, aCb) { store.set(aId, emptySess, aCb); diff --git a/libs/passportVerify.js b/libs/passportVerify.js index 987e17d02..6ff7097e9 100644 --- a/libs/passportVerify.js +++ b/libs/passportVerify.js @@ -75,4 +75,4 @@ exports.verify = function (aId, aStrategy, aUsername, aLoggedIn, aDone) { } } ); -} +}; diff --git a/libs/remove.js b/libs/remove.js index 85d7a4e6c..528492faa 100644 --- a/libs/remove.js +++ b/libs/remove.js @@ -31,7 +31,7 @@ function removeable(aModel, aContent, aUser, aCallback) { // You can't remove yourself // You can only remove a remove a user with a lesser role than yourself if (aModel.modelName === 'User') { - return aCallback(aContent._id != aUser._id && aContent.role > aUser.role, + return aCallback(aContent._id !== aUser._id && aContent.role > aUser.role, aContent); } @@ -41,7 +41,7 @@ function removeable(aModel, aContent, aUser, aCallback) { // You can't remove your own content this way // When you remove your own content it's removed for good - if (aAuthor._id == aUser._id) { return aCallback(false, aAuthor); } + if (aAuthor._id === aUser._id) { return aCallback(false, aAuthor); } // You can only remove content by an author with a lesser user role aCallback(aAuthor.role > aUser.role, aAuthor); @@ -50,7 +50,7 @@ function removeable(aModel, aContent, aUser, aCallback) { exports.removeable = removeable; function remove(aModel, aContent, aUser, aReason, aCallback) { - var remove = new Remove({ + var removeModel = new Remove({ 'model': aModel.modelName, 'content': aContent.toObject(), 'removed': new Date(), @@ -60,7 +60,7 @@ function remove(aModel, aContent, aUser, aReason, aCallback) { '_removerId': aUser._id }); - remove.save(function (aErr, aRemove) { + removeModel.save(function (aErr, aRemove) { aContent.remove(function (aErr) { aCallback(aRemove); }); }); } @@ -112,7 +112,7 @@ exports.findDeadorAlive = function (aModel, aQuery, aUser, aCallback) { var rmQuery = { model: modelName }; if (!aErr && aContent) { return aCallback(true, aContent, null); } - if (modelName != 'User' && -1 === modelNames.indexOf(modelName)) { + if (modelName !== 'User' && -1 === modelNames.indexOf(modelName)) { return aCallback(null, null, null); } @@ -126,7 +126,7 @@ exports.findDeadorAlive = function (aModel, aQuery, aUser, aCallback) { return aCallback(false, null, aRemoved); } - aCallback(false, new model(aRemoved.content), aRemoved); // TODO: Ambiguous + aCallback(false, new aModel(aRemoved.content), aRemoved); // TODO: Ambiguous }); }); }; diff --git a/libs/repoManager.js b/libs/repoManager.js index ea9f8a8c2..a98eec54e 100644 --- a/libs/repoManager.js +++ b/libs/repoManager.js @@ -8,11 +8,9 @@ var isDbg = require('../libs/debug').isDbg; // var https = require('https'); var async = require('async'); -var util = require('util'); var _ = require('underscore'); var Strategy = require('../models/strategy').Strategy; -var User = require('../models/user').User; var nil = require('./helpers').nil; var github = require('../libs/githubClient'); @@ -38,7 +36,7 @@ function fetchRaw(aHost, aPath, aCallback) { var req = https.request(options, function (aRes) { var bufs = []; - if (aRes.statusCode != 200) { console.log(aRes.statusCode); return aCallback([new Buffer('')]); } + if (aRes.statusCode !== 200) { console.log(aRes.statusCode); return aCallback([new Buffer('')]); } else { aRes.on('data', function (aD) { bufs.push(aD); }); // TODO: Non-descript function parm aRes.on('end', function () { @@ -102,7 +100,6 @@ RepoManager.prototype.loadScripts = function (aCallback, aUpdate) { var scriptStorage = require('../controllers/scriptStorage'); var arrayOfRepos = this.makeRepoArray(); var that = this; - var scripts = []; // TODO: remove usage of makeRepoArray since it causes redundant looping arrayOfRepos.forEach(function (aRepo) { @@ -161,7 +158,6 @@ Repo.prototype.fetchUserScripts = function (aCallback) { // Looks for user script in the current directory // and initiates searches on subdirectories Repo.prototype.parseTree = function (aTree, aPath, aDone) { - var object; var trees = []; var that = this; var repos = this.manager.repos; diff --git a/libs/templateHelpers.js b/libs/templateHelpers.js index 4b62d74fd..9518e3694 100644 --- a/libs/templateHelpers.js +++ b/libs/templateHelpers.js @@ -27,10 +27,10 @@ var paginateTemplate = function (aOpts) { for (var i = Math.max(1, currentPage - distVisible); i <= Math.min(currentPage + distVisible, lastPage); i++) linkedPages.push(i); - if (firstVisible && linkedPages.length > 0 && linkedPages[0] != 1) + if (firstVisible && linkedPages.length > 0 && linkedPages[0] !== 1) linkedPages.splice(0, 0, 1); // insert the value 1 at index 0 - if (lastVisible && linkedPages.length > 0 && linkedPages[linkedPages.length - 1] != lastPage) + if (lastVisible && linkedPages.length > 0 && linkedPages[linkedPages.length - 1] !== lastPage) linkedPages.push(lastPage); var html = ''; @@ -38,7 +38,7 @@ var paginateTemplate = function (aOpts) { for (var i = 0; i < linkedPages.length; i++) { var linkedPage = linkedPages[i]; html += ' Date: Sat, 29 Nov 2014 14:17:12 +0100 Subject: [PATCH 2/4] Removed Ambiguous comment; --- libs/remove.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remove.js b/libs/remove.js index 528492faa..42869a3b5 100644 --- a/libs/remove.js +++ b/libs/remove.js @@ -126,7 +126,7 @@ exports.findDeadorAlive = function (aModel, aQuery, aUser, aCallback) { return aCallback(false, null, aRemoved); } - aCallback(false, new aModel(aRemoved.content), aRemoved); // TODO: Ambiguous + aCallback(false, new aModel(aRemoved.content), aRemoved); }); }); }; From 207e14797983b5913750d9144ed4bbbe2c368761 Mon Sep 17 00:00:00 2001 From: Jeroen van Warmerdam Date: Mon, 1 Dec 2014 20:19:32 +0100 Subject: [PATCH 3/4] Revert all `user._id === user._id` changes; --- controllers/admin.js | 2 +- controllers/issue.js | 10 +++++----- controllers/script.js | 6 +++--- controllers/user.js | 12 ++++++------ libs/flag.js | 2 +- libs/remove.js | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/controllers/admin.js b/controllers/admin.js index ac66fa87c..3678aa7e5 100644 --- a/controllers/admin.js +++ b/controllers/admin.js @@ -181,7 +181,7 @@ exports.adminUserUpdate = function (aReq, aRes, aNext) { // User var user = options.user = modelParser.parseUser(aUserData); - options.isYou = authedUser && user && authedUser._id === user._id; + options.isYou = authedUser && user && authedUser._id == user._id; //--- diff --git a/controllers/issue.js b/controllers/issue.js index c2ddeff86..c5a412181 100644 --- a/controllers/issue.js +++ b/controllers/issue.js @@ -53,7 +53,7 @@ exports.list = function (aReq, aRes, aNext) { // Script var script = options.script = modelParser.parseScript(scriptData); - options.isOwner = authedUser && authedUser._id === script._authorId; + options.isOwner = authedUser && authedUser._id == script._authorId; // Category var category = {}; @@ -167,7 +167,7 @@ exports.view = function (aReq, aRes, aNext) { // Script var script = options.script = modelParser.parseScript(aScriptData); - options.isOwner = authedUser && authedUser._id === script._authorId; + options.isOwner = authedUser && authedUser._id == script._authorId; // Category var category = {}; @@ -185,8 +185,8 @@ exports.view = function (aReq, aRes, aNext) { // Discussion var discussion = options.discussion = modelParser.parseDiscussion(aDiscussionData); modelParser.parseIssue(discussion); - options.canClose = authedUser && (authedUser._id === script._authorId || authedUser._id === discussion._authorId); - options.canOpen = authedUser && authedUser._id === script._authorId; + options.canClose = authedUser && (authedUser._id == script._authorId || authedUser._id == discussion._authorId); + options.canOpen = authedUser && authedUser._id == script._authorId; // commentListQuery var commentListQuery = Comment.find(); @@ -273,7 +273,7 @@ exports.open = function (aReq, aRes, aNext) { // Script var script = options.script = modelParser.parseScript(aScriptData); - options.isOwner = authedUser && authedUser._id === script._authorId; + options.isOwner = authedUser && authedUser._id == script._authorId; // Category var category = {}; diff --git a/controllers/script.js b/controllers/script.js index 4abf743d2..a5ab8fbca 100644 --- a/controllers/script.js +++ b/controllers/script.js @@ -317,7 +317,7 @@ exports.view = function (aReq, aRes, aNext) { // Script var script = options.script = modelParser.parseScript(aScriptData); - options.isOwner = authedUser && authedUser._id === script._authorId; + options.isOwner = authedUser && authedUser._id == script._authorId; modelParser.renderScript(script); script.installNameSlug = installNameSlug; script.scriptPermalinkInstallPageUrl = 'http://' + aReq.get('host') + script.scriptInstallPageUrl; @@ -382,7 +382,7 @@ exports.edit = function (aReq, aRes, aNext) { // Page metadata var script = options.script = modelParser.parseScript(aScriptData); - options.isOwner = authedUser && authedUser._id === script._authorId; + options.isOwner = authedUser && authedUser._id == script._authorId; pageMetadata(options, ['Edit', script.name, (script.isLib ? 'Libraries' : 'Scripts')], script.name); @@ -477,7 +477,7 @@ exports.vote = function (aReq, aRes, aNext) { if (!aScript.rating) { aScript.rating = 0; } if (!aScript.votes) { aScript.votes = 0; } - if (user._id === aScript._authorId || (!aVoteModel && unvote)) { + if (user._id == aScript._authorId || (!aVoteModel && unvote)) { return aRes.redirect(url); } else if (!aVoteModel) { aVoteModel = new Vote({ diff --git a/controllers/user.js b/controllers/user.js index 048880346..a133d11ff 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -243,7 +243,7 @@ exports.view = function (aReq, aRes, aNext) { // User var user = options.user = modelParser.parseUser(aUserData); user.aboutRendered = renderMd(user.about); - options.isYou = authedUser && user && authedUser._id === user._id; + options.isYou = authedUser && user && authedUser._id == user._id; // Page metadata pageMetadata(options, [user.name, 'Users']); @@ -298,7 +298,7 @@ exports.userCommentListPage = function (aReq, aRes, aNext) { // User var user = options.user = modelParser.parseUser(aUserData); - options.isYou = authedUser && user && authedUser._id === user._id; + options.isYou = authedUser && user && authedUser._id == user._id; // Page metadata pageMetadata(options, [user.name, 'Users']); @@ -382,7 +382,7 @@ exports.userScriptListPage = function (aReq, aRes, aNext) { // User var user = options.user = modelParser.parseUser(aUserData); - options.isYou = authedUser && user && authedUser._id === user._id; + options.isYou = authedUser && user && authedUser._id == user._id; // Page metadata pageMetadata(options, [user.name, 'Users']); @@ -474,7 +474,7 @@ exports.userEditProfilePage = function (aReq, aRes, aNext) { // User var user = options.user = modelParser.parseUser(aUserData); - options.isYou = authedUser && user && authedUser._id === user._id; + options.isYou = authedUser && user && authedUser._id == user._id; // Page metadata pageMetadata(options, [user.name, 'Users']); @@ -534,7 +534,7 @@ exports.userEditPreferencesPage = function (aReq, aRes, aNext) { // User var user = options.user = modelParser.parseUser(aUserData); - options.isYou = authedUser && user && authedUser._id === user._id; + options.isYou = authedUser && user && authedUser._id == user._id; // Page metadata pageMetadata(options, [user.name, 'Users']); @@ -1450,7 +1450,7 @@ exports.editScript = function (aReq, aRes, aNext) { // Script var script = options.script = modelParser.parseScript(aScriptData); - options.isOwner = authedUser && authedUser._id === script._authorId; + options.isOwner = authedUser && authedUser._id == script._authorId; modelParser.renderScript(script); script.installNameSlug = installNameSlug; script.scriptPermalinkInstallPageUrl = 'http://' + aReq.get('host') + script.scriptInstallPageUrl; diff --git a/libs/flag.js b/libs/flag.js index 740b974f6..ade3c87c8 100644 --- a/libs/flag.js +++ b/libs/flag.js @@ -35,7 +35,7 @@ function flaggable(aModel, aContent, aUser, aCallback) { if (!aAuthor) { return aCallback(false); } // You can't flag your own content - if (aAuthor._id === aUser._id) { return aCallback(false); } + if (aAuthor._id == aUser._id) { return aCallback(false); } // Content belonging to an admin or above cannot be flagged if (aAuthor.role < 3) { return aCallback(aAuthor.role > 2, aAuthor); } diff --git a/libs/remove.js b/libs/remove.js index 42869a3b5..18024baa9 100644 --- a/libs/remove.js +++ b/libs/remove.js @@ -41,7 +41,7 @@ function removeable(aModel, aContent, aUser, aCallback) { // You can't remove your own content this way // When you remove your own content it's removed for good - if (aAuthor._id === aUser._id) { return aCallback(false, aAuthor); } + if (aAuthor._id == aUser._id) { return aCallback(false, aAuthor); } // You can only remove content by an author with a lesser user role aCallback(aAuthor.role > aUser.role, aAuthor); From 59a68a0898dafe1751a7e8f8c81bdc2f6a074275 Mon Sep 17 00:00:00 2001 From: Jeroen van Warmerdam Date: Tue, 2 Dec 2014 21:09:04 +0100 Subject: [PATCH 4/4] Revert all `===` comparison with db models; --- controllers/scriptStorage.js | 6 +++--- controllers/user.js | 2 +- libs/flag.js | 2 +- libs/modelParser.js | 2 +- libs/remove.js | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/controllers/scriptStorage.js b/controllers/scriptStorage.js index 23683d3a7..ad29bc07d 100644 --- a/controllers/scriptStorage.js +++ b/controllers/scriptStorage.js @@ -268,7 +268,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) { if (!scriptName) { return aCallback(null); } if (!isLibrary && aMeta.oujs && aMeta.oujs.author - && aMeta.oujs.author !== aUser.name && aMeta.oujs.collaborator) { + && aMeta.oujs.author != aUser.name && aMeta.oujs.collaborator) { collaborators = aMeta.oujs.collaborator; if ((typeof collaborators === 'string' && collaborators === aUser.name) @@ -327,8 +327,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) { } else { // Script already exists. if (!aScript.isLib) { - if (collaborators && (aScript.meta.oujs && aScript.meta.oujs.author !== aMeta.oujs.author - || (aScript.meta.oujs && JSON.stringify(aScript.meta.oujs.collaborator) !== + if (collaborators && (aScript.meta.oujs && aScript.meta.oujs.author != aMeta.oujs.author + || (aScript.meta.oujs && JSON.stringify(aScript.meta.oujs.collaborator) != JSON.stringify(aMeta.oujs.collaborator)))) { return aCallback(null); } diff --git a/controllers/user.js b/controllers/user.js index 00f0a89b5..b50bb475e 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -1371,7 +1371,7 @@ function getExistingScript(aReq, aOptions, aAuthedUser, aCallback) { aOptions.source = Buffer.concat(bufs).toString('utf8'); aOptions.original = aScript.installName; aOptions.url = aReq.url; - aOptions.owner = aAuthedUser && (aScript._authorId === aAuthedUser._id + aOptions.owner = aAuthedUser && (aScript._authorId == aAuthedUser._id || collaborators.indexOf(aAuthedUser.name) > -1); aOptions.username = aAuthedUser ? aAuthedUser.name : null; aOptions.isLib = aScript.isLib; diff --git a/libs/flag.js b/libs/flag.js index ade3c87c8..22139fd44 100644 --- a/libs/flag.js +++ b/libs/flag.js @@ -26,7 +26,7 @@ function flaggable(aModel, aContent, aUser, aCallback) { // to police the site administration if (aModel.modelName === 'User') { return getFlag(aModel, aContent, aUser, function (aFlag) { - aCallback(aContent._id !== aUser._id && aContent.role > 2, aContent, aFlag); + aCallback(aContent._id != aUser._id && aContent.role > 2, aContent, aFlag); }); } diff --git a/libs/modelParser.js b/libs/modelParser.js index abd4dcd1f..d144f62d4 100644 --- a/libs/modelParser.js +++ b/libs/modelParser.js @@ -327,7 +327,7 @@ var parseDiscussion = function (aDiscussionData) { var recentCommentors = []; if (discussion.author) recentCommentors.push(discussion.author); - if (discussion.lastCommentor !== discussion.author) + if (discussion.lastCommentor != discussion.author) recentCommentors.push(discussion.lastCommentor); recentCommentors = _.map(recentCommentors, function (aUsername) { return { diff --git a/libs/remove.js b/libs/remove.js index 18024baa9..2adf0ccec 100644 --- a/libs/remove.js +++ b/libs/remove.js @@ -31,7 +31,7 @@ function removeable(aModel, aContent, aUser, aCallback) { // You can't remove yourself // You can only remove a remove a user with a lesser role than yourself if (aModel.modelName === 'User') { - return aCallback(aContent._id !== aUser._id && aContent.role > aUser.role, + return aCallback(aContent._id != aUser._id && aContent.role > aUser.role, aContent); }