Skip to content

Commit

Permalink
jshint improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
chaudhryjunaid committed Oct 29, 2015
1 parent b5bbabb commit 72b4cf9
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 16 deletions.
13 changes: 11 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"couch" : false, // CouchDB
"devel" : true, // Development/debugging (alert, confirm, etc)
"dojo" : false, // Dojo Toolkit
"jasmine" : false, // Jasmine
"jasmine" : true, // Jasmine
"jquery" : false, // jQuery
"mocha" : true, // Mocha
"mootools" : false, // MooTools
Expand All @@ -89,5 +89,14 @@
"yui" : false, // Yahoo User Interface

// Custom Globals
"globals" : {} // additional predefined global variables
"globals" : {
"angular": true,
"describe": true,
"it": true,
"expect": true,
"beforeEach": true,
"afterEach": true,
"module": true,
"inject": true
} // additional predefined global variables
}
5 changes: 3 additions & 2 deletions app/controllers/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* Module dependencies.
*/
var StandardError = require('standard-error');
var db = require('../../config/sequelize');

/**
Expand Down Expand Up @@ -33,7 +34,7 @@ exports.create = function(req, res) {
// save and return and instance of article on the res object.
db.Article.create(req.body).then(function(article){
if(!article){
return res.send('users/signup', {errors: err});
return res.send('users/signup', {errors: new StandardError('Article could not be created')});
} else {
return res.jsonp(article);
}
Expand Down Expand Up @@ -111,7 +112,7 @@ exports.all = function(req, res) {
* Article authorizations routing middleware
*/
exports.hasAuthorization = function(req, res, next) {
if (req.article.User.id != req.user.id) {
if (req.article.User.id !== req.user.id) {
return res.send(401, 'User is not authorized');
}
next();
Expand Down
18 changes: 11 additions & 7 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ exports.session = function(req, res) {
/**
* Create user
*/
exports.create = function(req, res) {
exports.create = function(req, res, next) {
var message = null;

var user = db.User.build(req.body);
Expand All @@ -62,7 +62,9 @@ exports.create = function(req, res) {

user.save().then(function(){
req.login(user, function(err){
if(err) return next(err);
if(err) {
return next(err);
}
res.redirect('/');
});
}).catch(function(err){
Expand All @@ -84,8 +86,10 @@ exports.me = function(req, res) {
* Find user by id
*/
exports.user = function(req, res, next, id) {
User.find({where : { id: id }}).then(function(user){
if (!user) return next(new Error('Failed to load User ' + id));
db.User.find({where : { id: id }}).then(function(user){
if (!user) {
return next(new Error('Failed to load User ' + id));
}
req.profile = user;
next();
}).catch(function(err){
Expand All @@ -98,7 +102,7 @@ exports.user = function(req, res, next, id) {
*/
exports.requiresLogin = function(req, res, next) {
if (!req.isAuthenticated()) {
return res.send(401, 'User is not authorized');
return res.status(401).send('User is not authorized');
}
next();
};
Expand All @@ -107,8 +111,8 @@ exports.requiresLogin = function(req, res, next) {
* User authorizations routing middleware
*/
exports.hasAuthorization = function(req, res, next) {
if (req.profile.id != req.user.id) {
return res.send(401, 'User is not authorized');
if (req.profile.id !== req.user.id) {
return res.status(401).send('User is not authorized');
}
next();
};
4 changes: 3 additions & 1 deletion app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ module.exports = function(sequelize, DataTypes) {
return this.encryptPassword(plainText, this.salt) === this.hashedPassword;
},
encryptPassword: function(password, salt) {
if (!password || !salt) return '';
if (!password || !salt) {
return '';
}
salt = new Buffer(salt, 'base64');
return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
}
Expand Down
3 changes: 2 additions & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module.exports = function(grunt) {
jshint: {
all:['gruntfile.js', 'public/js/**/*.js', 'test/mocha/**/*.js', 'test/karma/**/*.js', 'app/**/*.js'],
options: {
jshintrc: '.jshintrc'
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
}
},
copy: {
Expand Down
4 changes: 3 additions & 1 deletion package.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.2.0",
"private": false,
"author": "Jeff Potter",
"license" : "MIT",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/jpotts18/mean-stack-relational.git"
Expand Down Expand Up @@ -35,6 +35,7 @@
"grunt-copy": "latest",
"grunt-env": "latest",
"jade": "1.3.1",
"jshint-stylish": "^2.0.1",
"lodash": "latest",
"method-override": "2.3.2",
"morgan": "1.5.2",
Expand All @@ -47,6 +48,7 @@
"proxyquire": "^1.6.0",
"sequelize": "^3.2.0",
"serve-favicon": "2.2.0",
"standard-error": "^1.1.0",
"view-helpers": "latest",
"winston": "latest"
},
Expand Down
2 changes: 1 addition & 1 deletion public/js/controllers/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ angular.module('mean.articles').controller('ArticlesController', ['$scope', '$ro
article.$remove();

for (var i in $scope.articles) {
if ($scope.articles[i] == article) {
if ($scope.articles[i] === article) {
$scope.articles.splice(i, 1);
}
}
Expand Down
4 changes: 3 additions & 1 deletion public/js/init.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
angular.element(document).ready(function() {
//Fixing facebook bug with redirect
if (window.location.hash == "#_=_") window.location.hash = "#!";
if (window.location.hash === "#_=_") {
window.location.hash = "#!";
}

//Then init the app
angular.bootstrap(document, ['mean']);
Expand Down

0 comments on commit 72b4cf9

Please sign in to comment.