From 822d7ca7b2d8bbff405264fbca39c838937bd619 Mon Sep 17 00:00:00 2001 From: Amos Haviv Date: Wed, 25 Dec 2013 16:36:33 +0200 Subject: [PATCH] Properly run JSHint --- .jshintrc | 10 +++---- app/controllers/articles.js | 16 +++++++++-- app/controllers/index.js | 8 ++---- app/controllers/users.js | 12 ++++---- app/models/article.js | 3 +- app/models/user.js | 8 ++++-- app/views/includes/foot.jade | 2 +- bower.json | 29 +++++++++----------- config/config.js | 2 ++ config/env/all.js | 2 ++ config/env/development.js | 2 ++ config/env/production.js | 2 ++ config/env/test.js | 2 ++ config/env/travis.json | 27 ------------------ config/express.js | 2 ++ config/middlewares/authorization.js | 2 ++ config/passport.js | 2 ++ config/routes.js | 2 ++ gruntfile.js | 14 ++++++---- package.json | 2 +- public/js/app.js | 2 ++ public/js/config.js | 4 ++- public/js/controllers/articles.js | 12 ++++---- public/js/controllers/header.js | 10 ++++--- public/js/controllers/index.js | 2 ++ public/js/directives.js | 1 + public/js/filters.js | 1 + public/js/init.js | 4 ++- public/js/services/articles.js | 4 ++- public/js/services/global.js | 4 ++- server.js | 2 ++ test/karma/karma.conf.js | 2 ++ test/karma/unit/controllers/articles.spec.js | 8 ++---- test/karma/unit/controllers/headers.spec.js | 12 ++------ test/karma/unit/controllers/index.spec.js | 12 ++------ test/mocha/article/model.js | 5 ++-- test/mocha/user/model.js | 5 ++-- 37 files changed, 125 insertions(+), 114 deletions(-) delete mode 100644 config/env/travis.json diff --git a/.jshintrc b/.jshintrc index 8a7233d7a3..66eeef6739 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,7 +1,6 @@ { "node": true, // Enable globals available when code is running inside of the NodeJS runtime environment. "browser": true, // Standard browser globals e.g. `window`, `document`. - "es5": true, // Allow EcmaScript 5 syntax. "esnext": true, // Allow ES.next specific features such as `const` and `let`. "bitwise": false, // Prohibit bitwise operators (&, |, ^, etc.). "camelcase": false, // Permit only camelcase for `var` and `object indexes`. @@ -15,7 +14,7 @@ "regexp": true, // Prohibit `.` and `[^...]` in regular expressions. "undef": true, // Require all non-global variables be declared before they are used. "unused": true, // Warn unused variables. - "strict": false, // Require `use strict` pragma in every file. + "strict": true, // Require `use strict` pragma in every file. "trailing": true, // Prohibit trailing whitespaces. "smarttabs": false, // Suppresses warnings about mixed tabs and spaces "globals": { // Globals variables. @@ -31,10 +30,11 @@ "beforeEach", "after", "afterEach", - "it" + "it", + "inject", + "expect" ], "indent": 4, // Specify indentation spacing - "maxlen": 120, // Max line lenght - "devel": false, // Allow development statements e.g. `console.log();`. + "devel": true, // Allow development statements e.g. `console.log();`. "noempty": true // Prohibit use of empty blocks. } \ No newline at end of file diff --git a/app/controllers/articles.js b/app/controllers/articles.js index 4f80a197c8..681a69dc0d 100644 --- a/app/controllers/articles.js +++ b/app/controllers/articles.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Module dependencies. */ @@ -46,7 +48,14 @@ exports.update = function(req, res) { article = _.extend(article, req.body); article.save(function(err) { - res.jsonp(article); + if (err) { + return res.send('users/signup', { + errors: err.errors, + article: article + }); + } else { + res.jsonp(article); + } }); }; @@ -58,8 +67,9 @@ exports.destroy = function(req, res) { article.remove(function(err) { if (err) { - res.render('error', { - status: 500 + return res.send('users/signup', { + errors: err.errors, + article: article }); } else { res.jsonp(article); diff --git a/app/controllers/index.js b/app/controllers/index.js index e547ac50ea..4ccf91656a 100644 --- a/app/controllers/index.js +++ b/app/controllers/index.js @@ -1,11 +1,7 @@ -/** - * Module dependencies. - */ -var mongoose = require('mongoose'); - +'use strict'; exports.render = function(req, res) { res.render('index', { - user: req.user ? JSON.stringify(req.user) : "null" + user: req.user ? JSON.stringify(req.user) : 'null' }); }; diff --git a/app/controllers/users.js b/app/controllers/users.js index 21b0685c22..c9be6af013 100755 --- a/app/controllers/users.js +++ b/app/controllers/users.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Module dependencies. */ @@ -7,7 +9,7 @@ var mongoose = require('mongoose'), /** * Auth callback */ -exports.authCallback = function(req, res, next) { +exports.authCallback = function(req, res) { res.redirect('/'); }; @@ -49,19 +51,19 @@ exports.session = function(req, res) { /** * Create user */ -exports.create = function(req, res) { +exports.create = function(req, res, next) { var user = new User(req.body); var message = null; user.provider = 'local'; user.save(function(err) { if (err) { - switch(err.code){ + switch (err.code) { case 11000: case 11001: message = 'Username already exists'; break; - default: + default: message = 'Please fill all the required fields'; } @@ -98,4 +100,4 @@ exports.user = function(req, res, next, id) { req.profile = user; next(); }); -}; +}; \ No newline at end of file diff --git a/app/models/article.js b/app/models/article.js index fca75909ec..75f63c2b37 100644 --- a/app/models/article.js +++ b/app/models/article.js @@ -1,8 +1,9 @@ +'use strict'; + /** * Module dependencies. */ var mongoose = require('mongoose'), - config = require('../../config/config'), Schema = mongoose.Schema; diff --git a/app/models/user.js b/app/models/user.js index 4befd08903..ca11b81128 100755 --- a/app/models/user.js +++ b/app/models/user.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Module dependencies. */ @@ -104,7 +106,7 @@ UserSchema.methods = { * @api public */ makeSalt: function() { - return crypto.randomBytes(16).toString('base64'); + return crypto.randomBytes(16).toString('base64'); }, /** @@ -116,9 +118,9 @@ UserSchema.methods = { */ encryptPassword: function(password) { if (!password || !this.salt) return ''; - salt = new Buffer(this.salt, 'base64'); + var salt = new Buffer(this.salt, 'base64'); return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64'); } }; -mongoose.model('User', UserSchema); +mongoose.model('User', UserSchema); \ No newline at end of file diff --git a/app/views/includes/foot.jade b/app/views/includes/foot.jade index 881aa2748a..e57f92f5da 100755 --- a/app/views/includes/foot.jade +++ b/app/views/includes/foot.jade @@ -27,4 +27,4 @@ script(type='text/javascript', src='/js/init.js') if (process.env.NODE_ENV == 'development') //Livereload script rendered - script(type='text/javascript', src='http://localhost:35729/livereload.js') + script(type='text/javascript', src='http://' + req.host + ':35729/livereload.js') diff --git a/bower.json b/bower.json index 27e3bc159f..33f816f090 100644 --- a/bower.json +++ b/bower.json @@ -1,17 +1,14 @@ { - "name": "mean", - "version": "0.1.0", - "dependencies": { - "angular": "latest", - "angular-resource": "latest", - "angular-cookies": "latest", - "angular-mocks": "latest", - "angular-route": "latest", - "bootstrap": "2.3.2", - "angular-bootstrap": "0.7.0", - "angular-ui-utils": "0.0.4" - }, - "resolutions": { - "angular": "1.2.6" - } -} \ No newline at end of file + "name": "mean", + "version": "0.1.0", + "dependencies": { + "angular": "latest", + "angular-resource": "latest", + "angular-cookies": "latest", + "angular-mocks": "latest", + "angular-route": "latest", + "bootstrap": "2.3.2", + "angular-bootstrap": "0.7.0", + "angular-ui-utils": "0.0.4" + } +} diff --git a/config/config.js b/config/config.js index aeec0cc264..b4b4230022 100644 --- a/config/config.js +++ b/config/config.js @@ -1,3 +1,5 @@ +'use strict'; + var _ = require('lodash'); // Load app configuration diff --git a/config/env/all.js b/config/env/all.js index fd5f16fabd..22d15f7e62 100644 --- a/config/env/all.js +++ b/config/env/all.js @@ -1,3 +1,5 @@ +'use strict'; + var path = require('path'), rootPath = path.normalize(__dirname + '/../..'); diff --git a/config/env/development.js b/config/env/development.js index 656ffbaabf..c726d33355 100644 --- a/config/env/development.js +++ b/config/env/development.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { db: "mongodb://localhost/mean-dev", app: { diff --git a/config/env/production.js b/config/env/production.js index 8683ef3b2f..d37a2787c8 100644 --- a/config/env/production.js +++ b/config/env/production.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { db: "mongodb://localhost/mean", app: { diff --git a/config/env/test.js b/config/env/test.js index 257ccb7c9a..2a21399897 100644 --- a/config/env/test.js +++ b/config/env/test.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { db: "mongodb://localhost/mean-test", port: 3001, diff --git a/config/env/travis.json b/config/env/travis.json deleted file mode 100644 index 2a2ccc980c..0000000000 --- a/config/env/travis.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "db": "mongodb://localhost/mean-travis", - "port": 3001, - "app": { - "name": "MEAN - A Modern Stack - Test on travis" - }, - "facebook": { - "clientID": "APP_ID", - "clientSecret": "APP_SECRET", - "callbackURL": "http://localhost:3000/auth/facebook/callback" - }, - "twitter": { - "clientID": "CONSUMER_KEY", - "clientSecret": "CONSUMER_SECRET", - "callbackURL": "http://localhost:3000/auth/twitter/callback" - }, - "github": { - "clientID": "APP_ID", - "clientSecret": "APP_SECRET", - "callbackURL": "http://localhost:3000/auth/github/callback" - }, - "google": { - "clientID": "APP_ID", - "clientSecret": "APP_SECRET", - "callbackURL": "http://localhost:3000/auth/google/callback" - } -} \ No newline at end of file diff --git a/config/express.js b/config/express.js index 7cbd0881db..6bc2202730 100755 --- a/config/express.js +++ b/config/express.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Module dependencies. */ diff --git a/config/middlewares/authorization.js b/config/middlewares/authorization.js index 9732488c0d..8bbb0b2a38 100755 --- a/config/middlewares/authorization.js +++ b/config/middlewares/authorization.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Generic require login routing middleware */ diff --git a/config/passport.js b/config/passport.js index 7ee2ca60f7..ef4eaa4dde 100755 --- a/config/passport.js +++ b/config/passport.js @@ -1,3 +1,5 @@ +'use strict'; + var mongoose = require('mongoose'), LocalStrategy = require('passport-local').Strategy, TwitterStrategy = require('passport-twitter').Strategy, diff --git a/config/routes.js b/config/routes.js index 5b428a9914..2456e868fe 100755 --- a/config/routes.js +++ b/config/routes.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = function(app, passport, auth) { //User Routes var users = require('../app/controllers/users'); diff --git a/gruntfile.js b/gruntfile.js index 9fa2d61a19..a85f100fc4 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = function(grunt) { // Project Configuration grunt.initConfig({ @@ -10,7 +12,7 @@ module.exports = function(grunt) { }, }, js: { - files: ['public/js/**', 'app/**/*.js'], + files: ['gruntfile.js', 'server.js', 'app/**/*.js', 'public/js/**', 'test/**/*.js'], tasks: ['jshint'], options: { livereload: true, @@ -31,7 +33,10 @@ module.exports = function(grunt) { }, jshint: { all: { - src: ['gruntfile.js', 'public/js/**/*.js', 'test/mocha/**/*.js', 'test/karma/**/*.js', 'app/**/*.js'] + src: ['gruntfile.js', 'server.js', 'app/**/*.js', 'public/js/**', 'test/**/*.js'], + options: { + jshintrc: true + } } }, nodemon: { @@ -39,9 +44,8 @@ module.exports = function(grunt) { options: { file: 'server.js', args: [], - ignoredFiles: ['README.md', 'node_modules/**', '.DS_Store'], + ignoredFiles: ['public/**'], watchedExtensions: ['js'], - watchedFolders: ['app', 'config'], debug: true, delayTime: 1, env: { @@ -92,4 +96,4 @@ module.exports = function(grunt) { //Test task. grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']); -}; +}; \ No newline at end of file diff --git a/package.json b/package.json index 1c63d94b93..c83d12d35f 100755 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "engines": { "node": "0.10.x", - "npm": "1.2.x" + "npm": "1.3.x" }, "scripts": { "start": "node node_modules/grunt-cli/bin/grunt", diff --git a/public/js/app.js b/public/js/app.js index eff39efa34..21a6e85327 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -1,3 +1,5 @@ +'use strict'; + angular.module('mean', ['ngCookies', 'ngResource', 'ngRoute', 'ui.bootstrap', 'ui.route', 'mean.system', 'mean.articles']); angular.module('mean.system', []); diff --git a/public/js/config.js b/public/js/config.js index 25000cadf8..113062582b 100644 --- a/public/js/config.js +++ b/public/js/config.js @@ -1,3 +1,5 @@ +'use strict'; + //Setting up route angular.module('mean').config(['$routeProvider', function($routeProvider) { @@ -26,6 +28,6 @@ angular.module('mean').config(['$routeProvider', //Setting HTML5 Location Mode angular.module('mean').config(['$locationProvider', function($locationProvider) { - $locationProvider.hashPrefix("!"); + $locationProvider.hashPrefix('!'); } ]); \ No newline at end of file diff --git a/public/js/controllers/articles.js b/public/js/controllers/articles.js index 66dac1f440..09afb5aa6d 100644 --- a/public/js/controllers/articles.js +++ b/public/js/controllers/articles.js @@ -1,3 +1,5 @@ +'use strict'; + angular.module('mean.articles').controller('ArticlesController', ['$scope', '$routeParams', '$location', 'Global', 'Articles', function ($scope, $routeParams, $location, Global, Articles) { $scope.global = Global; @@ -7,19 +9,19 @@ angular.module('mean.articles').controller('ArticlesController', ['$scope', '$ro content: this.content }); article.$save(function(response) { - $location.path("articles/" + response._id); + $location.path('articles/' + response._id); }); - this.title = ""; - this.content = ""; + this.title = ''; + this.content = ''; }; $scope.remove = function(article) { if (article) { - article.$remove(); + article.$remove(); for (var i in $scope.articles) { - if ($scope.articles[i] == article) { + if ($scope.articles[i] === article) { $scope.articles.splice(i, 1); } } diff --git a/public/js/controllers/header.js b/public/js/controllers/header.js index 1c1b04fcf2..d1f74efb42 100644 --- a/public/js/controllers/header.js +++ b/public/js/controllers/header.js @@ -1,12 +1,14 @@ +'use strict'; + angular.module('mean.system').controller('HeaderController', ['$scope', 'Global', function ($scope, Global) { $scope.global = Global; $scope.menu = [{ - "title": "Articles", - "link": "articles" + 'title': 'Articles', + 'link': 'articles' }, { - "title": "Create New Article", - "link": "articles/create" + 'title': 'Create New Article', + 'link': 'articles/create' }]; $scope.isCollapsed = false; diff --git a/public/js/controllers/index.js b/public/js/controllers/index.js index 2687573559..6ef537efc0 100644 --- a/public/js/controllers/index.js +++ b/public/js/controllers/index.js @@ -1,3 +1,5 @@ +'use strict'; + angular.module('mean.system').controller('IndexController', ['$scope', 'Global', function ($scope, Global) { $scope.global = Global; }]); \ No newline at end of file diff --git a/public/js/directives.js b/public/js/directives.js index e69de29bb2..a726efc43f 100644 --- a/public/js/directives.js +++ b/public/js/directives.js @@ -0,0 +1 @@ +'use strict'; \ No newline at end of file diff --git a/public/js/filters.js b/public/js/filters.js index e69de29bb2..a726efc43f 100644 --- a/public/js/filters.js +++ b/public/js/filters.js @@ -0,0 +1 @@ +'use strict'; \ No newline at end of file diff --git a/public/js/init.js b/public/js/init.js index 939eee057c..31fe6d53ab 100644 --- a/public/js/init.js +++ b/public/js/init.js @@ -1,6 +1,8 @@ +'use strict'; + 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']); diff --git a/public/js/services/articles.js b/public/js/services/articles.js index 2d496701ca..69f9be88a7 100644 --- a/public/js/services/articles.js +++ b/public/js/services/articles.js @@ -1,5 +1,7 @@ +'use strict'; + //Articles service used for articles REST endpoint -angular.module('mean.articles').factory("Articles", ['$resource', function($resource) { +angular.module('mean.articles').factory('Articles', ['$resource', function($resource) { return $resource('articles/:articleId', { articleId: '@_id' }, { diff --git a/public/js/services/global.js b/public/js/services/global.js index 93071aa474..b31388ea72 100644 --- a/public/js/services/global.js +++ b/public/js/services/global.js @@ -1,5 +1,7 @@ +'use strict'; + //Global service for global variables -angular.module('mean.system').factory("Global", [ +angular.module('mean.system').factory('Global', [ function() { var _this = this; _this._data = { diff --git a/server.js b/server.js index f1fb60e37b..183f0a5ef3 100755 --- a/server.js +++ b/server.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Module dependencies. */ diff --git a/test/karma/karma.conf.js b/test/karma/karma.conf.js index 5e21e453bf..b3694a4910 100644 --- a/test/karma/karma.conf.js +++ b/test/karma/karma.conf.js @@ -1,3 +1,5 @@ +'use strict'; + // Karma configuration // Generated on Sat Oct 05 2013 22:00:14 GMT+0700 (ICT) diff --git a/test/karma/unit/controllers/articles.spec.js b/test/karma/unit/controllers/articles.spec.js index b572991cae..410c9bd238 100644 --- a/test/karma/unit/controllers/articles.spec.js +++ b/test/karma/unit/controllers/articles.spec.js @@ -1,11 +1,9 @@ -(function() { - 'use strict'; +'use strict'; +(function() { // Articles Controller Spec describe('MEAN controllers', function() { - describe('ArticlesController', function() { - // The $resource service augments the response object with methods for updating and deleting the resource. // If we were to use the standard toEqual matcher, our tests would fail because the test values would not match // the responses exactly. To solve the problem, we use a newly-defined toEqualData Jasmine matcher. @@ -195,8 +193,6 @@ expect(scope.articles.length).toBe(0); })); - }); - }); }()); \ No newline at end of file diff --git a/test/karma/unit/controllers/headers.spec.js b/test/karma/unit/controllers/headers.spec.js index 98ea968f6b..6a88308996 100644 --- a/test/karma/unit/controllers/headers.spec.js +++ b/test/karma/unit/controllers/headers.spec.js @@ -1,15 +1,12 @@ -(function() { - 'use strict'; +'use strict'; +(function() { describe('MEAN controllers', function() { - describe('HeaderController', function() { - // Load the controllers module beforeEach(module('mean')); - var scope, - HeaderController; + var scope, HeaderController; beforeEach(inject(function($controller, $rootScope) { scope = $rootScope.$new(); @@ -24,9 +21,6 @@ expect(scope.global).toBeTruthy(); }); - }); - }); - })(); \ No newline at end of file diff --git a/test/karma/unit/controllers/index.spec.js b/test/karma/unit/controllers/index.spec.js index 3a32aa5aa4..73fdb5b89e 100644 --- a/test/karma/unit/controllers/index.spec.js +++ b/test/karma/unit/controllers/index.spec.js @@ -1,15 +1,12 @@ -(function() { - 'use strict'; +'use strict'; +(function() { describe('MEAN controllers', function() { - describe('IndexController', function() { - // Load the controllers module beforeEach(module('mean')); - var scope, - IndexController; + var scope, IndexController; beforeEach(inject(function($controller, $rootScope) { scope = $rootScope.$new(); @@ -24,9 +21,6 @@ expect(scope.global).toBeTruthy(); }); - }); - }); - })(); \ No newline at end of file diff --git a/test/mocha/article/model.js b/test/mocha/article/model.js index 3afe68c4f8..9377f577d5 100644 --- a/test/mocha/article/model.js +++ b/test/mocha/article/model.js @@ -1,8 +1,9 @@ +'use strict'; + /** * Module dependencies. */ var should = require('should'), - app = require('../../../server'), mongoose = require('mongoose'), User = mongoose.model('User'), Article = mongoose.model('Article'); @@ -22,7 +23,7 @@ describe('', function() { password: 'password' }); - user.save(function(err) { + user.save(function() { article = new Article({ title: 'Article Title', content: 'Article Content', diff --git a/test/mocha/user/model.js b/test/mocha/user/model.js index 2ed19dc636..fada6580a0 100644 --- a/test/mocha/user/model.js +++ b/test/mocha/user/model.js @@ -1,13 +1,14 @@ +'use strict'; + /** * Module dependencies. */ var should = require('should'), - app = require('../../../server'), mongoose = require('mongoose'), User = mongoose.model('User'); //Globals -var user; +var user, user2; //The tests describe('', function() {