Skip to content

Commit 7cbdd5e

Browse files
digawpdarrachequesne
authored andcommitted
[style] Add ESlint (socketio#385)
1 parent e008ffe commit 7cbdd5e

22 files changed

+606
-572
lines changed

Diff for: .eslintrc.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "standard",
3+
"parser": "babel-eslint",
4+
"rules": {
5+
"yoda": 0,
6+
"semi": [2, "always"],
7+
"no-extra-semi": 2,
8+
"semi-spacing": [2, { "before": false, "after": true }]
9+
}
10+
}

Diff for: examples/latency/index.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
* Module dependencies.
44
*/
55

6-
var express = require('express')
7-
, app = express()
8-
, server = require('http').createServer(app)
9-
, enchilada = require('enchilada')
10-
, io = require('engine.io').attach(server);
6+
var express = require('express');
7+
var app = express();
8+
var server = require('http').createServer(app);
9+
var enchilada = require('enchilada');
10+
var io = require('engine.io').attach(server);
1111

1212
app.use(enchilada({
1313
src: __dirname + '/public',
1414
debug: true
1515
}));
1616
app.use(express.static(__dirname + '/public'));
17-
app.get('/', function(req, res, next){
17+
app.get('/', function (req, res, next) {
1818
res.sendfile('index.html');
1919
});
2020

21-
io.on('connection', function(socket){
22-
socket.on('message', function(v){
21+
io.on('connection', function (socket) {
22+
socket.on('message', function (v) {
2323
socket.send('pong');
2424
});
2525
});
2626

2727
var port = process.env.PORT || 3000;
28-
server.listen(port, function(){
29-
console.log('\033[96mlistening on localhost:' + port + ' \033[39m');
28+
server.listen(port, function () {
29+
console.log('\x1B[96mlistening on localhost:' + port + ' \x1B[39m');
3030
});

Diff for: examples/latency/public/index.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33
* Module dependencies.
44
*/
55

6-
var SmoothieChart = require("smoothie").SmoothieChart
7-
, TimeSeries = require("smoothie").TimeSeries
8-
, eio = require("engine.io-client");
9-
6+
var SmoothieChart = require('smoothie').SmoothieChart;
7+
var TimeSeries = require('smoothie').TimeSeries;
8+
var eio = require('engine.io-client');
109

1110
// helper
1211

13-
function $(id){ return document.getElementById(id); }
12+
function $ (id) { return document.getElementById(id); }
1413

1514
// chart
1615

1716
var smoothie;
1817
var time;
1918

20-
function render(){
19+
function render () {
2120
if (smoothie) smoothie.stop();
2221
$('chart').width = document.body.clientWidth;
2322
smoothie = new SmoothieChart();
@@ -33,25 +32,25 @@ function render(){
3332
// socket
3433
var socket = new eio.Socket();
3534
var last;
36-
function send(){
37-
last = new Date;
35+
function send () {
36+
last = new Date();
3837
socket.send('ping');
3938
$('transport').innerHTML = socket.transport.name;
4039
}
41-
socket.on('open', function(){
40+
socket.on('open', function () {
4241
if ($('chart').getContext) {
4342
render();
4443
window.onresize = render;
4544
}
4645
send();
4746
});
48-
socket.on('close', function(){
47+
socket.on('close', function () {
4948
if (smoothie) smoothie.stop();
5049
$('transport').innerHTML = '(disconnected)';
5150
});
52-
socket.on('message', function(){
53-
var latency = new Date - last;
51+
socket.on('message', function () {
52+
var latency = new Date() - last;
5453
$('latency').innerHTML = latency + 'ms';
55-
if (time) time.append(+new Date, latency);
54+
if (time) time.append(+new Date(), latency);
5655
setTimeout(send, 100);
5756
});

Diff for: gulpfile.js

+34-21
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,52 @@
1-
var gulp = require('gulp');
2-
var mocha = require('gulp-mocha');
3-
var babel = require("gulp-babel");
4-
var nsp = require('gulp-nsp');
1+
const gulp = require('gulp');
2+
const mocha = require('gulp-mocha');
3+
const babel = require('gulp-babel');
4+
const nsp = require('gulp-nsp');
5+
const eslint = require('gulp-eslint');
56

6-
var TESTS = 'test/*.js';
7-
var REPORTER = 'dot';
7+
const TESTS = 'test/*.js';
8+
const REPORTER = 'dot';
89

9-
gulp.task("default", ["transpile"]);
10+
gulp.task('default', ['transpile']);
1011

11-
gulp.task('test', ['nsp'], function(){
12-
if (parseInt(process.versions.node) < 4 && process.env.EIO_WS_ENGINE == 'uws') {
13-
console.info("Node version < 4, skipping tests with uws engine");
14-
process.exit();
15-
}
16-
return gulp.src(TESTS, {read: false})
12+
gulp.task('test', ['nsp', 'lint'], function () {
13+
if (parseInt(process.versions.node, 10) < 4 && process.env.EIO_WS_ENGINE === 'uws') {
14+
console.info('Node version < 4, skipping tests with uws engine');
15+
process.exit();
16+
}
17+
return gulp.src(TESTS, {read: false})
1718
.pipe(mocha({
1819
slow: 500,
1920
reporter: REPORTER,
2021
bail: true
2122
}))
22-
.once('error', function(){
23+
.once('error', function (err) {
24+
console.error(err.stack);
2325
process.exit(1);
2426
})
25-
.once('end', function(){
27+
.once('end', function () {
2628
process.exit();
2729
});
2830
});
2931

32+
gulp.task('lint', function () {
33+
return gulp.src([
34+
'*.js',
35+
'lib/**/*.js',
36+
'test/**/*.js'
37+
])
38+
.pipe(eslint())
39+
.pipe(eslint.format())
40+
.pipe(eslint.failAfterError());
41+
});
42+
3043
// By default, individual js files are transformed by babel and exported to /dist
31-
gulp.task("transpile", function(){
32-
return gulp.src(["lib/*.js","lib/transports/*.js"], { base: 'lib' })
33-
.pipe(babel({ "presets": ["es2015"] }))
34-
.pipe(gulp.dest("dist"));
44+
gulp.task('transpile', function () {
45+
return gulp.src(['lib/**/*.js'], { base: 'lib' })
46+
.pipe(babel({ 'presets': ['es2015'] }))
47+
.pipe(gulp.dest('dist'));
3548
});
3649

3750
gulp.task('nsp', function (cb) {
38-
nsp({package: __dirname + '/package.json'}, cb)
39-
})
51+
nsp({package: __dirname + '/package.json'}, cb);
52+
});

Diff for: lib/engine.io.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var http = require('http');
1717
* @api public
1818
*/
1919

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

8989
exports.listen = listen;
9090

91-
function listen(port, options, fn) {
92-
if ('function' == typeof options) {
91+
function listen (port, options, fn) {
92+
if ('function' === typeof options) {
9393
fn = options;
9494
options = {};
9595
}
@@ -106,7 +106,7 @@ function listen(port, options, fn) {
106106
engine.httpServer = server;
107107

108108
return engine;
109-
};
109+
}
110110

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

120120
exports.attach = attach;
121121

122-
function attach(server, options) {
122+
function attach (server, options) {
123123
var engine = new exports.Server(options);
124124
engine.attach(server, options);
125125
return engine;
126-
};
126+
}

0 commit comments

Comments
 (0)