Skip to content

Commit 13edaca

Browse files
committed
Add eslint and apply it's suggestions
1 parent a8a270f commit 13edaca

File tree

9 files changed

+27
-15
lines changed

9 files changed

+27
-15
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage
2+
examples
3+
src/public

.eslintrc.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"it": false,
66
"beforeEach": false,
77
"before": false,
8-
"after": false
8+
"after": false,
9+
"Chart": false
910
},
1011
"rules": {
1112
"import/no-extraneous-dependencies": [
12-
"error",
13-
{
13+
"error", {
1414
"peerDependencies": true
1515
}
1616
],
1717
"no-param-reassign": "off"
1818
}
19-
}
19+
}

circle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ machine:
33
version: 4.0.0
44
test:
55
pre:
6+
- npm run eslint
67
- nvm install 6.9.1 && nvm use 6.9.1 && npm test
78
- nvm use node && npm test
89
- snyk test

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./src/middleware-wrapper');
1+
module.exports = require('./src/middleware-wrapper');

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@
5151
"test": "mocha --recursive",
5252
"snyk-protect": "snyk protect",
5353
"prepublish": "npm run snyk-protect",
54-
"example": "cd examples && npm start"
54+
"example": "cd examples && npm start",
55+
"eslint": "eslint . --fix"
5556
},
5657
"devDependencies": {
5758
"bithound": "^1.7.0",
5859
"chai": "^3.5.0",
60+
"eslint": "^3.9.1",
61+
"eslint-config-airbnb": "^12.0.0",
62+
"eslint-plugin-import": "^1.16.0",
63+
"eslint-plugin-jsx-a11y": "^2.2.3",
64+
"eslint-plugin-react": "^6.5.0",
5965
"istanbul": "^0.4.5",
6066
"mocha": "^3.0.2",
6167
"sinon": "^1.17.5",

src/helpers/on-headers-listener.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module.exports = (statusCode, startTime, spans) => {
22
const diff = process.hrtime(startTime);
3-
const responseTime = diff[0] * 1e3 + diff[1] * 1e-6;
3+
const responseTime = ((diff[0] * 1e3) + diff[1]) * 1e-6;
44
const category = Math.floor(statusCode / 100);
55

66
spans.forEach((span) => {
77
const last = span.responses[span.responses.length - 1];
8-
if (last !== undefined && last.timestamp / 1000 + span.interval > Date.now() / 1000) {
9-
last[category]++;
10-
last.count++;
11-
last.mean = last.mean + ((responseTime - last.mean) / last.count);
8+
if (last !== undefined && (last.timestamp / 1000) + span.interval > Date.now() / 1000) {
9+
last[category] += 1;
10+
last.count += 1;
11+
last.mean += ((responseTime - last.mean) / last.count);
1212
} else {
1313
span.responses.push({
1414
2: category === 2 ? 1 : 0,

src/helpers/socket-io-init.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint strict: "off" */
2+
23
'use strict';
34

45
const socketIo = require('socket.io');
@@ -14,15 +15,15 @@ module.exports = (server, config) => {
1415
io = socketIo(server);
1516
}
1617

17-
io.on('connection', socket => {
18+
io.on('connection', (socket) => {
1819
socket.emit('esm_start', config.spans);
1920
socket.on('esm_change', () => {
2021
socket.emit('esm_start', config.spans);
2122
});
2223
});
2324

2425

25-
config.spans.forEach(span => {
26+
config.spans.forEach((span) => {
2627
span.os = [];
2728
span.responses = [];
2829
const interval = setInterval(() => gatherOsMetrics(io, span), span.interval * 1000);

src/middleware-wrapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const middlewareWrapper = (config) => {
2323
if (req.path === config.path) {
2424
res.send(renderedHtml);
2525
} else {
26-
onHeaders(res, () => { onHeadersListener(res.statusCode, startTime, config.spans) });
26+
onHeaders(res, () => { onHeadersListener(res.statusCode, startTime, config.spans); });
2727
next();
2828
}
2929
};

test/helpers/validate.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-unused-expressions */
12
const chai = require('chai');
23

34
chai.should();
@@ -56,7 +57,7 @@ describe('helpers', () => {
5657
});
5758

5859
describe('when config is valid', () => {
59-
const customConfig = { title: 'Custom title', path: '/custom-path', spans: [{}, {}, {}], port: 9999, websocket: {} }
60+
const customConfig = { title: 'Custom title', path: '/custom-path', spans: [{}, {}, {}], port: 9999, websocket: {} };
6061
const config = validate(customConfig);
6162

6263
it(`then title === ${customConfig.title}`, () => {

0 commit comments

Comments
 (0)