Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some JSHint fixes #458

Merged
merged 6 commits into from
Dec 2, 2014
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 0 additions & 4 deletions controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: authedUser.role } }, function (aErr, aUsers) {
var i = 0;
options.users = [];

aUsers.forEach(function (aUser) {
Expand Down Expand Up @@ -168,7 +166,6 @@ exports.adminUserUpdate = function (aReq, aRes, aNext) {

//
var options = {};
var tasks = [];

// Session
authedUser = options.authedUser = modelParser.parseUser(authedUser);
Expand Down Expand Up @@ -428,7 +425,6 @@ exports.authAsUser = function (aReq, aRes, aNext) {

//
var options = {};
var tasks = [];

// Session
authedUser = options.authedUser = modelParser.parseUser(authedUser);
Expand Down
3 changes: 1 addition & 2 deletions controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 here

} else {
strategyInstance._verify =
function (aToken, aRefreshOrSecretToken, aProfile, aDone) {
Expand Down
1 change: 0 additions & 1 deletion controllers/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ exports.createComment = function (aReq, aRes, aNext) {
var topic = aReq.params.topic;
var authedUser = aReq.session.user;
var content = aReq.body['comment-content'];
var commentId = aReq.body['comment-id']; // for editing

if (!authedUser) { return aNext(); }

Expand Down
1 change: 0 additions & 1 deletion controllers/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ exports.list = function (aReq, aRes) {

var setupGroupSidePanel = function (aOptions) {
// Shortcuts
var group = aOptions.group;
var authedUser = aOptions.authedUser;

// Mod
Expand Down
4 changes: 2 additions & 2 deletions controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ exports.home = function (aReq, aRes) {
pageMetadata(options, ['Flagged Scripts', 'Moderation']);
}
}
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 here

function render() { aRes.render('pages/scriptListPage', options); }
function asyncComplete() { preRender(); render(); }
async.parallel(tasks, asyncComplete);
Expand Down Expand Up @@ -217,7 +217,7 @@ exports.register = function (aReq, aRes) {
var githubStrategy = _.findWhere(options.strategies, { strat: 'github' });
if (githubStrategy)
githubStrategy.selected = true;
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 here

function render() { aRes.render('pages/loginPage', options); }
function asyncComplete() { preRender(); render(); }
async.parallel(tasks, asyncComplete);
Expand Down
2 changes: 1 addition & 1 deletion controllers/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ exports.open = function (aReq, aRes, aNext) {
function preRender() {
// Page metadata
pageMetadata(options, ['New Issue', script.name]);
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 here

function render() { aRes.render('pages/scriptNewIssuePage', options); }
function asyncComplete() { preRender(); render(); }

Expand Down
1 change: 0 additions & 1 deletion controllers/moderation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ exports.removedItemPage = function (aReq, aRes, aNext) {

//
var options = {};
var tasks = [];

// Session
authedUser = options.authedUser = modelParser.parseUser(authedUser);
Expand Down
9 changes: 0 additions & 9 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -266,7 +264,6 @@ var getScriptPageTasks = function (aOptions) {

var setupScriptSidePanel = function (aOptions) {
// Shortcuts
var script = aOptions.script;
var authedUser = aOptions.authedUser;

// User
Expand All @@ -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({
Expand Down Expand Up @@ -355,8 +350,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({
Expand Down Expand Up @@ -398,8 +391,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 () {
Expand Down
8 changes: 3 additions & 5 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a FYI I see an incomplete optimization from someone here which is why JSHint plucked line 237 out.

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down
21 changes: 6 additions & 15 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,7 +96,6 @@ var getUserPageTasks = function (aOptions) {

// Shortcuts
var user = aOptions.user;
var authedUser = aOptions.authedUser;

//--- Tasks

Expand Down Expand Up @@ -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(); } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 here

async.parallel(tasks, asyncComplete);
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -461,8 +456,6 @@ exports.userScriptListPage = function (aReq, aRes, aNext) {
exports.userEditProfilePage = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;

var username = aReq.params.username;

User.findOne({
_id: authedUser._id
}, function (aErr, aUserData) {
Expand Down Expand Up @@ -858,7 +851,6 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {

//
var options = {};
var tasks = [];

// Session
authedUser = options.authedUser = modelParser.parseUser(authedUser);
Expand Down Expand Up @@ -1001,7 +993,7 @@ exports.userGitHubRepoPage = function (aReq, aRes, aNext) {
options.repo = aRepo;
options.repoAsEncoded = {
default_branch: encodeURI(options.repo.default_branch)
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 here


github.gitdata.getJavascriptBlobs({
user: encodeURIComponent(aRepo.owner.login),
Expand All @@ -1025,7 +1017,7 @@ exports.userGitHubRepoPage = function (aReq, aRes, aNext) {

aCallback(null);
},
], aCallback)
], aCallback);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 here

});

//---
Expand Down Expand Up @@ -1092,7 +1084,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;

Expand All @@ -1111,7 +1102,7 @@ exports.userManageGitHubPage = function (aReq, aRes, aNext) {
},
function (aGithubUser, aCallback) {
options.githubUser = aGithubUser;
console.log(githubUser);
console.log(aGithubUser);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 here

User.findOne({
_id: authedUser._id
}, aCallback);
Expand Down Expand Up @@ -1148,7 +1139,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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be interesting to know how this works... I don't believe I've seen this but we've all come a long way since then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zren
So for clarity sake since I've never seen this before yesterday... if someone names a repo starting out with "_all" this will allegedly import everything in that GH repo including libraries and userscripts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never used this before too, but you can access that page at https://openuserjs.org/users/marti/github

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting and thanks Jerone... might be useful to have that listed at https://openuserjs.org/user/add/scripts so it's not an orphaned route. Since this is fixing this it might be useful to have an issue with this in it. e.g. #468

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because the logic behind that route is awful. It can go through hundreds of github api requests (Edit: which times out if the user has a lot of repos with logs of files/folders) and doesn't list all repositories if the users list of repos is paginated.

The route should be removed since I rewrote it to handle pagination and the like but sizzle wanted it left there. Rather than confusing abuser with 2 ways to

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import from github, I only linked to the less resource intensive method with pagination and left the old route unlinked to in case sizzle wanted to use it to import all scripts in a repo for testing.

aReponame = aRepo;
aRepo = aRepos[aReponame];

Expand Down Expand Up @@ -1380,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;
Expand Down
1 change: 0 additions & 1 deletion libs/collectiveRating.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
2 changes: 1 addition & 1 deletion libs/flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
4 changes: 2 additions & 2 deletions libs/githubClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 here since it's not a string.

return aCallback(util.format('Status Code %s', aResponse.statusCode));

aCallback(null, aBody);
Expand Down
5 changes: 2 additions & 3 deletions libs/modelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 here

if (_.isNumber(aCategory.roleReqToPostTopic)) {
return aUser.role <= aCategory.roleReqToPostTopic;
} else {
Expand Down
2 changes: 1 addition & 1 deletion libs/modifySessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably fixed a bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably +1 here. ;)


async.each(aUser.sessionIds, function (aId, aCb) {
store.set(aId, emptySess, aCb);
Expand Down
2 changes: 1 addition & 1 deletion libs/passportVerify.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ exports.verify = function (aId, aStrategy, aUsername, aLoggedIn, aDone) {
}
}
);
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 here

Loading