Skip to content

Commit

Permalink
[style] Add ESlint (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
digawp authored and darrachequesne committed Oct 31, 2016
1 parent e008ffe commit 7cbdd5e
Show file tree
Hide file tree
Showing 22 changed files with 606 additions and 572 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "standard",
"parser": "babel-eslint",
"rules": {
"yoda": 0,
"semi": [2, "always"],
"no-extra-semi": 2,
"semi-spacing": [2, { "before": false, "after": true }]
}
}
20 changes: 10 additions & 10 deletions examples/latency/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
* Module dependencies.
*/

var express = require('express')
, app = express()
, server = require('http').createServer(app)
, enchilada = require('enchilada')
, io = require('engine.io').attach(server);
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var enchilada = require('enchilada');
var io = require('engine.io').attach(server);

app.use(enchilada({
src: __dirname + '/public',
debug: true
}));
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res, next){
app.get('/', function (req, res, next) {
res.sendfile('index.html');
});

io.on('connection', function(socket){
socket.on('message', function(v){
io.on('connection', function (socket) {
socket.on('message', function (v) {
socket.send('pong');
});
});

var port = process.env.PORT || 3000;
server.listen(port, function(){
console.log('\033[96mlistening on localhost:' + port + ' \033[39m');
server.listen(port, function () {
console.log('\x1B[96mlistening on localhost:' + port + ' \x1B[39m');
});
25 changes: 12 additions & 13 deletions examples/latency/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
* Module dependencies.
*/

var SmoothieChart = require("smoothie").SmoothieChart
, TimeSeries = require("smoothie").TimeSeries
, eio = require("engine.io-client");

var SmoothieChart = require('smoothie').SmoothieChart;
var TimeSeries = require('smoothie').TimeSeries;
var eio = require('engine.io-client');

// helper

function $(id){ return document.getElementById(id); }
function $ (id) { return document.getElementById(id); }

// chart

var smoothie;
var time;

function render(){
function render () {
if (smoothie) smoothie.stop();
$('chart').width = document.body.clientWidth;
smoothie = new SmoothieChart();
Expand All @@ -33,25 +32,25 @@ function render(){
// socket
var socket = new eio.Socket();
var last;
function send(){
last = new Date;
function send () {
last = new Date();
socket.send('ping');
$('transport').innerHTML = socket.transport.name;
}
socket.on('open', function(){
socket.on('open', function () {
if ($('chart').getContext) {
render();
window.onresize = render;
}
send();
});
socket.on('close', function(){
socket.on('close', function () {
if (smoothie) smoothie.stop();
$('transport').innerHTML = '(disconnected)';
});
socket.on('message', function(){
var latency = new Date - last;
socket.on('message', function () {
var latency = new Date() - last;
$('latency').innerHTML = latency + 'ms';
if (time) time.append(+new Date, latency);
if (time) time.append(+new Date(), latency);
setTimeout(send, 100);
});
55 changes: 34 additions & 21 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var babel = require("gulp-babel");
var nsp = require('gulp-nsp');
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const babel = require('gulp-babel');
const nsp = require('gulp-nsp');
const eslint = require('gulp-eslint');

var TESTS = 'test/*.js';
var REPORTER = 'dot';
const TESTS = 'test/*.js';
const REPORTER = 'dot';

gulp.task("default", ["transpile"]);
gulp.task('default', ['transpile']);

gulp.task('test', ['nsp'], function(){
if (parseInt(process.versions.node) < 4 && process.env.EIO_WS_ENGINE == 'uws') {
console.info("Node version < 4, skipping tests with uws engine");
process.exit();
}
return gulp.src(TESTS, {read: false})
gulp.task('test', ['nsp', 'lint'], function () {
if (parseInt(process.versions.node, 10) < 4 && process.env.EIO_WS_ENGINE === 'uws') {
console.info('Node version < 4, skipping tests with uws engine');
process.exit();
}
return gulp.src(TESTS, {read: false})
.pipe(mocha({
slow: 500,
reporter: REPORTER,
bail: true
}))
.once('error', function(){
.once('error', function (err) {
console.error(err.stack);
process.exit(1);
})
.once('end', function(){
.once('end', function () {
process.exit();
});
});

gulp.task('lint', function () {
return gulp.src([
'*.js',
'lib/**/*.js',
'test/**/*.js'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

// By default, individual js files are transformed by babel and exported to /dist
gulp.task("transpile", function(){
return gulp.src(["lib/*.js","lib/transports/*.js"], { base: 'lib' })
.pipe(babel({ "presets": ["es2015"] }))
.pipe(gulp.dest("dist"));
gulp.task('transpile', function () {
return gulp.src(['lib/**/*.js'], { base: 'lib' })
.pipe(babel({ 'presets': ['es2015'] }))
.pipe(gulp.dest('dist'));
});

gulp.task('nsp', function (cb) {
nsp({package: __dirname + '/package.json'}, cb)
})
nsp({package: __dirname + '/package.json'}, cb);
});
12 changes: 6 additions & 6 deletions lib/engine.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var http = require('http');
* @api public
*/

exports = module.exports = function() {
exports = module.exports = function () {
// backwards compatible use as `.attach`
// if first argument is an http server
if (arguments.length && arguments[0] instanceof http.Server) {
Expand Down Expand Up @@ -88,8 +88,8 @@ exports.parser = require('engine.io-parser');

exports.listen = listen;

function listen(port, options, fn) {
if ('function' == typeof options) {
function listen (port, options, fn) {
if ('function' === typeof options) {
fn = options;
options = {};
}
Expand All @@ -106,7 +106,7 @@ function listen(port, options, fn) {
engine.httpServer = server;

return engine;
};
}

/**
* Captures upgrade requests for a http.Server.
Expand All @@ -119,8 +119,8 @@ function listen(port, options, fn) {

exports.attach = attach;

function attach(server, options) {
function attach (server, options) {
var engine = new exports.Server(options);
engine.attach(server, options);
return engine;
};
}
Loading

0 comments on commit 7cbdd5e

Please sign in to comment.