Skip to content

Commit

Permalink
fix(code): add lintlovin and fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
simme committed Apr 26, 2015
1 parent 0103d2b commit 0ddc8b5
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 30 deletions.
1 change: 1 addition & 0 deletions .editorconfig
1 change: 1 addition & 0 deletions .jscsrc
1 change: 1 addition & 0 deletions .jshintrc
8 changes: 8 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*jslint node: true */
'use strict';

var lintlovin = require('lintlovin');

module.exports = function (grunt) {
lintlovin.initConfig(grunt);
};
11 changes: 4 additions & 7 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ var API = module.exports = {};
var fs = require('fs');
var path = require('path');
var jstream = require('JSONStream');
var _ = require('lodash');
var md5 = require('MD5');
var comments = require('./lib/commentstream');
var Comments = require('./lib/commentstream');
var xss = require('./lib/xss');
var uglify = require('uglifyjs');

//
// ## JavaScript
Expand Down Expand Up @@ -96,6 +93,7 @@ API.post = function postComment(request, reply) {
}

function doneFiltering(err) {
console.log(err);
//if (err) {
// var response = reply({
// success: false,
Expand Down Expand Up @@ -155,10 +153,9 @@ API.get = function getComments(request, reply) {
// https://github.com/hapijs/hapi/issues/2368
// Or in JSONStream...
responseStream._readableState = {};
var commentStream = new comments();
var commentStream = new Comments();
stream.pipe(commentStream).pipe(responseStream);

var response = reply(responseStream)
reply(responseStream)
.type('application/json');
};

2 changes: 0 additions & 2 deletions lib/commentstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,3 @@ CommentStream.prototype._transform = function _transform(chunk, encoding, done)
this.push(chunk);
done();
};


7 changes: 4 additions & 3 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SocketManager.prototype.connection = function connection(client) {
SocketManager.prototype.close = function close(connection) {
for (var i in this.channels) {
var index = this.channels[i].indexOf(connection);
if (index != -1) {
if (index !== -1) {
this.channels[i].splice(index, 1);
if (this.channels[i].length === 0) {
delete(this.channels[i]);
Expand Down Expand Up @@ -85,7 +85,9 @@ SocketManager.prototype.subscribe = function subscribe(channel, connection) {
//
SocketManager.prototype.dbListener = function (key, value) {
var channel = this.channels[key.split('~')[0]];
if (!channel) return;
if (!channel) {
return;
}

This comment has been minimized.

Copy link
@voxpelli

voxpelli Apr 26, 2015

Lintlovin doesn't require newlines for single-statement blocks – it only requires the {}

This comment has been minimized.

Copy link
@simme

simme Apr 26, 2015

Author Owner

Yeah, I know. Just felt better to do it this way. Have one lines in the client-side JS though^^


var i = channel.length - 1;
for (i; i >= 0; i--) {
Expand All @@ -95,4 +97,3 @@ SocketManager.prototype.dbListener = function (key, value) {
client.send(JSON.stringify(value));
}
};

6 changes: 2 additions & 4 deletions lib/spam.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ module.exports.register = function (plugin, options, next) {
if (err) {
resp.message = 'Failed to save comment.';
console.log(err);
}
else if (isSpam) {
} else if (isSpam) {
resp.message = 'Comment rejected.';
}
else {
} else {
code = 200;
resp.success = true;
resp.message = 'ya';
Expand Down
1 change: 0 additions & 1 deletion lib/xss.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,3 @@ module.exports = function filter(html, options, callback) {
module.exports.defaultWhitelist = ['a', 'p', 'strong', 'em', 'b', 'i'];
module.exports.attributeOK = ['href'];
module.exports.noFollowLinks = true;

13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"homepage": "https://github.com/simme/node-tala",
"scripts": {
"start": "node tala.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node -e \"require('grunt').tasks(['test']);\"",
"test-all": "node -e \"require('grunt').tasks(['test-all']);\"",
"prepush": "npm test"
},
"keywords": [
"comments",
Expand All @@ -28,5 +30,12 @@
"nodemailer": "~0.6.0",
"uglifyjs": "^2.4.10",
"ws": "~0.4.31"
},
"devDependencies": {
"grunt": "^0.4.5",
"husky": "^0.7.0",
"istanbul": "^0.3.13",
"lintlovin": "^1.15.1",
"mocha": "^2.2.4"
}
}
}
16 changes: 8 additions & 8 deletions tala.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ var hapi = require('hapi');
var levelup = require('levelup');
var path = require('path');
var _ = require('lodash');
var ws = require('ws');
var api = require('./api');
var sm = require('./lib/socket');
var SocketManager = require('./lib/socket');
var joi = require('joi');

//
Expand Down Expand Up @@ -63,17 +62,17 @@ function startServer() {
config: {
cache: {
privacy: 'public',
//expiresIn: 24 * 3600 * 1000
expiresIn: 24 * 3600 * 1000
},
cors: true
cors: cors
}
},
{
path: '/comment',
method: 'POST',
handler: api.post,
config: {
cors: true,
cors: cors,
payload: {
output: 'data',
parse: true
Expand All @@ -83,7 +82,7 @@ function startServer() {
payload: {
username: joi.string().min(1).max(32),
email: joi.string().email(),
comment: joi.string().min(1).max(1024*3),
comment: joi.string().min(1).max(1024 * 3),
resource: joi.string().min(1),
url: joi.string() // @FIXME: Validate URL
}
Expand All @@ -95,7 +94,7 @@ function startServer() {
method: 'GET',
handler: api.get,
config: {
cors: { origin: ['*'] }
cors: cors
}
}
]);
Expand Down Expand Up @@ -129,5 +128,6 @@ function startServer() {
});
});

var socketManager = new sm(server.listener, db);
/* jshint nonew: false */
new SocketManager(server.listener, db);
}
1 change: 0 additions & 1 deletion test/tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,3 @@ tt p://6 6.000146.0x7.147/">XSS</A>
<A HREF="javascript:document.location='http://www.google.com/'">XSS</A>

<A HREF="http://www.gohttp://www.google.com/ogle.com/">XSS</A>

6 changes: 4 additions & 2 deletions test/xss.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* globals suite, test */
/* jshint node: true */
'use strict';
var assert = require('assert');
var xss = require('./../lib/xss');

// Attack vectors copied from https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
var vectors = require('fs').readFileSync(__dirname + '/tests.txt', 'utf8');
//var vectors = require('fs').readFileSync(__dirname + '/tests.txt', 'utf8');

suite('XSS', function () {
test('Correctly removes non whitelisted tags.', function (done) {
Expand Down Expand Up @@ -34,4 +37,3 @@ suite('XSS', function () {
// t(parts[0], parts[1], done);
//});
});

0 comments on commit 0ddc8b5

Please sign in to comment.