Permalink
Browse files

style(examples): Unused deps, JSCS violations, gitignore

  • Loading branch information...
1 parent be86556 commit 728f097ddbc219346f878499ed878894555c4322 @jameswomack jameswomack committed Jun 19, 2015
View
@@ -9,4 +9,6 @@ examples/todoapp/node_modules
*.tgz
build
docs/*.json
-nbproject
+nbproject
+deps/javascriptlint
+deps/jsstyle
@@ -8,4 +8,5 @@ server.get('/echo/:name', function (req, res, next) {
server.listen(8080, function () {
console.log('ready');
-});
+});
+
@@ -95,7 +95,7 @@ var server = restify.createServer({
} else if (Buffer.isBuffer(body)) {
body = body.toString('base64');
} else {
- switch (typeof(body)) {
+ switch (typeof body) {
case 'boolean':
case 'number':
case 'string':
@@ -28,4 +28,5 @@ server.get({
server.listen(8080, function () {
console.log('listening: %s', server.url);
-});
+});
+
@@ -3,8 +3,6 @@
var util = require('util');
var assert = require('assert-plus');
-var bunyan = require('bunyan');
-var getopt = require('posix-getopt');
var restify = require('restify');
@@ -22,7 +20,6 @@ function TodoClient(options) {
assert.optionalString(options.url, 'options.url');
assert.optionalString(options.version, 'options.version');
- var self = this;
var ver = options.version || '~1.0';
this.client = restify.createClient({
@@ -3,4 +3,5 @@
module.exports = {
createClient: require('./client').createClient,
createServer: require('./server').createServer
-};
+};
+
@@ -96,13 +96,15 @@ function authenticate(req, res, next) {
}
var authz = req.authorization.basic;
+
if (!authz) {
res.setHeader('WWW-Authenticate', 'Basic realm="todoapp"');
next(new restify.UnauthorizedError('authentication required'));
return;
}
- if (authz.username !== req.allow.user || authz.password !== req.allow.pass) {
+ if (authz.username !== req.allow.user ||
+ authz.password !== req.allow.pass) {
next(new restify.ForbiddenError('invalid credentials'));
return;
}
@@ -276,8 +278,9 @@ function loadTodos(req, res, next) {
} else {
req.todos = files;
- if (req.params.name)
+ if (req.params.name) {
req.todo = req.dir + '/' + req.params.name;
+ }
req.log.debug({
todo: req.todo,
@@ -312,12 +315,6 @@ function putTodo(req, res, next) {
return;
}
- // Force the name to be what we sent this to
- var todo = {
- name: req.params.name,
- task: req.params.task
- };
-
fs.writeFile(req.todo, JSON.stringify(req.body), function (err) {
if (err) {
req.log.warn(err, 'putTodo: unable to save');
@@ -369,7 +366,7 @@ function createServer(options) {
server.use(restify.throttle({
burst: 10,
rate: 5,
- ip: true,
+ ip: true
}));
// Use the common stuff you probably want
@@ -385,6 +382,7 @@ function createServer(options) {
// at https://github.com/joyent/node-http-signature
server.use(function setup(req, res, next) {
req.dir = options.directory;
+
if (options.user && options.password) {
req.allow = {
user: options.user,
@@ -2,9 +2,7 @@
var fs = require('fs');
var path = require('path');
-var util = require('util');
-var assert = require('assert-plus');
var bunyan = require('bunyan');
var getopt = require('posix-getopt');
var restify = require('restify');
@@ -59,7 +57,7 @@ var LOG = bunyan.createLogger({
*/
function parseOptions() {
var option;
- var opts = {}
+ var opts = {};
var parser = new getopt.BasicParser('hvd:p:u:z:', process.argv);
while ((option = parser.getopt()) !== undefined) {
@@ -84,8 +82,10 @@ function parseOptions() {
// Allows us to set -vvv -> this little hackery
// just ensures that we're never < TRACE
LOG.level(Math.max(bunyan.TRACE, (LOG.level() - 10)));
- if (LOG.level() <= bunyan.DEBUG)
+
+ if (LOG.level() <= bunyan.DEBUG) {
LOG = LOG.child({src: true});
+ }
break;
case 'z':
@@ -103,8 +103,9 @@ function parseOptions() {
function usage(msg) {
- if (msg)
+ if (msg) {
console.error(msg);
+ }
var str = 'usage: ' +
NAME +
@@ -123,6 +124,7 @@ function usage(msg) {
// First setup our 'database'
var dir = path.normalize((options.directory || '/tmp') + '/todos');
+
try {
fs.mkdirSync(dir);
} catch (e) {
@@ -3,7 +3,6 @@
var fs = require('fs');
var bunyan = require('bunyan');
-var nodeunit = require('nodeunit');
var restify = require('restify');
var todo = require('../lib');
@@ -58,8 +57,10 @@ exports.listEmpty = function (t) {
t.ifError(err);
t.ok(todos);
t.ok(Array.isArray(todos));
- if (todos)
+
+ if (todos) {
t.equal(todos.length, 0);
+ }
t.done();
});
};
@@ -70,6 +71,7 @@ exports.create = function (t) {
CLIENT.create(task, function (err, todo) {
t.ifError(err);
t.ok(todo);
+
if (todo) {
t.ok(todo.name);
t.equal(todo.task, task);
@@ -84,6 +86,7 @@ exports.listAndGet = function (t) {
t.ifError(err);
t.ok(todos);
t.ok(Array.isArray(todos));
+
if (todos) {
t.equal(todos.length, 1);
CLIENT.get(todos[0], function (err2, todo) {
@@ -103,6 +106,7 @@ exports.update = function (t) {
t.ifError(err);
t.ok(todos);
t.ok(Array.isArray(todos));
+
if (todos) {
t.equal(todos.length, 1);
View
@@ -60,7 +60,6 @@
"backoff": "^2.4.0",
"bunyan": "1.3.4",
"csv": "^0.4.0",
- "deep-equal": "^1.0.0",
"escape-regexp-component": "^1.0.2",
"formidable": "^1.0.14",
"http-signature": "^0.10.0",

0 comments on commit 728f097

Please sign in to comment.