Skip to content

Commit 9851465

Browse files
authored
Merge pull request #302 from share/eslint
Linter fixes
2 parents 0b65164 + 40abc17 commit 9851465

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2957
-2751
lines changed

.eslintrc.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// The ESLint ecmaVersion argument is inconsistently used. Some rules will ignore it entirely, so if the rule has
2+
// been set, it will still error even if it's not applicable to that version number. Since Google sets these
3+
// rules, we have to turn them off ourselves.
4+
const DISABLED_ES6_OPTIONS = {
5+
'no-var': 'off',
6+
'prefer-rest-params': 'off'
7+
};
8+
9+
const SHAREDB_RULES = {
10+
// Comma dangle is not supported in ES3
11+
'comma-dangle': ['error', 'never'],
12+
// We control our own objects and prototypes, so no need for this check
13+
'guard-for-in': 'off',
14+
// Google prescribes different indents for different cases. Let's just use 2 spaces everywhere. Note that we have
15+
// to override ESLint's default of 0 indents for this.
16+
'indent': ['error', 2, {
17+
'SwitchCase': 1
18+
}],
19+
// Less aggressive line length than Google, which is especially useful when we have a lot of callbacks in our code
20+
'max-len': ['error',
21+
{
22+
code: 120,
23+
tabWidth: 2,
24+
ignoreUrls: true,
25+
}
26+
],
27+
// Google overrides the default ESLint behaviour here, which is slightly better for catching erroneously unused variables
28+
'no-unused-vars': ['error', {vars: 'all', args: 'after-used'}],
29+
// It's more readable to ensure we only have one statement per line
30+
'max-statements-per-line': ['error', {max: 1}],
31+
// as-needed quote props are easier to write
32+
'quote-props': ['error', 'as-needed'],
33+
'require-jsdoc': 'off',
34+
'valid-jsdoc': 'off'
35+
};
36+
37+
module.exports = {
38+
extends: 'google',
39+
parserOptions: {
40+
ecmaVersion: 3
41+
},
42+
rules: Object.assign(
43+
{},
44+
DISABLED_ES6_OPTIONS,
45+
SHAREDB_RULES
46+
),
47+
};

.jshintrc

Lines changed: 0 additions & 18 deletions
This file was deleted.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ node_js:
33
- "10"
44
- "8"
55
- "6"
6-
script: "npm run jshint && npm run test-cover"
6+
script: "npm run lint && npm run test-cover"
77
# Send coverage data to Coveralls
88
after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"

examples/counter/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function startServer() {
2929

3030
// Connect any incoming WebSocket connection to ShareDB
3131
var wss = new WebSocket.Server({server: server});
32-
wss.on('connection', function(ws, req) {
32+
wss.on('connection', function(ws) {
3333
var stream = new WebSocketJSONStream(ws);
3434
backend.listen(stream);
3535
});

examples/leaderboard/server/index.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
var http = require("http");
2-
var ShareDB = require("sharedb");
3-
var connect = require("connect");
1+
var http = require('http');
2+
var ShareDB = require('sharedb');
3+
var connect = require('connect');
44
var serveStatic = require('serve-static');
55
var ShareDBMingoMemory = require('sharedb-mingo-memory');
66
var WebSocketJSONStream = require('@teamwork/websocket-json-stream');
77
var WebSocket = require('ws');
8-
var util = require('util');
98

109
// Start ShareDB
11-
var share = ShareDB({db: new ShareDBMingoMemory()});
10+
var share = new ShareDB({db: new ShareDBMingoMemory()});
1211

1312
// Create a WebSocket server
1413
var app = connect();
1514
app.use(serveStatic('.'));
1615
var server = http.createServer(app);
1716
var wss = new WebSocket.Server({server: server});
1817
server.listen(8080);
19-
console.log("Listening on http://localhost:8080");
18+
console.log('Listening on http://localhost:8080');
2019

2120
// Connect any incoming WebSocket connection with ShareDB
22-
wss.on('connection', function(ws, req) {
21+
wss.on('connection', function(ws) {
2322
var stream = new WebSocketJSONStream(ws);
2423
share.listen(stream);
2524
});
2625

2726
// Create initial documents
2827
var connection = share.connect();
2928
connection.createFetchQuery('players', {}, {}, function(err, results) {
30-
if (err) { throw err; }
29+
if (err) {
30+
throw err;
31+
}
3132

3233
if (results.length === 0) {
33-
var names = ["Ada Lovelace", "Grace Hopper", "Marie Curie",
34-
"Carl Friedrich Gauss", "Nikola Tesla", "Claude Shannon"];
34+
var names = ['Ada Lovelace', 'Grace Hopper', 'Marie Curie',
35+
'Carl Friedrich Gauss', 'Nikola Tesla', 'Claude Shannon'];
3536

3637
names.forEach(function(name, index) {
3738
var doc = connection.get('players', ''+index);

examples/rich-text/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function startServer() {
3232

3333
// Connect any incoming WebSocket connection to ShareDB
3434
var wss = new WebSocket.Server({server: server});
35-
wss.on('connection', function(ws, req) {
35+
wss.on('connection', function(ws) {
3636
var stream = new WebSocketJSONStream(ws);
3737
backend.listen(stream);
3838
});

examples/textarea/client.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@ var sharedb = require('sharedb/lib/client');
22
var StringBinding = require('sharedb-string-binding');
33

44
// Open WebSocket connection to ShareDB server
5-
const WebSocket = require('reconnecting-websocket');
5+
var WebSocket = require('reconnecting-websocket');
66
var socket = new WebSocket('ws://' + window.location.host);
77
var connection = new sharedb.Connection(socket);
88

99
var element = document.querySelector('textarea');
1010
var statusSpan = document.getElementById('status-span');
11-
statusSpan.innerHTML = "Not Connected"
11+
statusSpan.innerHTML = 'Not Connected';
1212

13-
element.style.backgroundColor = "gray";
14-
socket.onopen = function(){
15-
statusSpan.innerHTML = "Connected"
16-
element.style.backgroundColor = "white";
13+
element.style.backgroundColor = 'gray';
14+
socket.onopen = function() {
15+
statusSpan.innerHTML = 'Connected';
16+
element.style.backgroundColor = 'white';
1717
};
1818

19-
socket.onclose = function(){
20-
statusSpan.innerHTML = "Closed"
21-
element.style.backgroundColor = "gray";
19+
socket.onclose = function() {
20+
statusSpan.innerHTML = 'Closed';
21+
element.style.backgroundColor = 'gray';
2222
};
2323

2424
socket.onerror = function() {
25-
statusSpan.innerHTML = "Error"
26-
element.style.backgroundColor = "red";
27-
}
25+
statusSpan.innerHTML = 'Error';
26+
element.style.backgroundColor = 'red';
27+
};
2828

2929
// Create local Doc instance mapped to 'examples' collection document with id 'textarea'
3030
var doc = connection.get('examples', 'textarea');
3131
doc.subscribe(function(err) {
3232
if (err) throw err;
33-
33+
3434
var binding = new StringBinding(element, doc, ['content']);
3535
binding.setup();
3636
});

examples/textarea/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function createDoc(callback) {
1414
doc.fetch(function(err) {
1515
if (err) throw err;
1616
if (doc.type === null) {
17-
doc.create({ content: '' }, callback);
17+
doc.create({content: ''}, callback);
1818
return;
1919
}
2020
callback();
@@ -29,7 +29,7 @@ function startServer() {
2929

3030
// Connect any incoming WebSocket connection to ShareDB
3131
var wss = new WebSocket.Server({server: server});
32-
wss.on('connection', function(ws, req) {
32+
wss.on('connection', function(ws) {
3333
var stream = new WebSocketJSONStream(ws);
3434
backend.listen(stream);
3535
});

lib/agent.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Agent.prototype.close = function(err) {
5656
};
5757

5858
Agent.prototype._cleanup = function() {
59-
6059
// Only clean up once if the stream emits both 'end' and 'close'.
6160
if (this.closed) return;
6261

@@ -265,7 +264,7 @@ Agent.prototype._open = function() {
265264
agent._handleMessage(request.data, callback);
266265
});
267266
});
268-
267+
269268
var cleanup = agent._cleanup.bind(agent);
270269
this.stream.on('end', cleanup);
271270
this.stream.on('close', cleanup);
@@ -333,7 +332,9 @@ Agent.prototype._handleMessage = function(request, callback) {
333332
};
334333
function getQueryOptions(request) {
335334
var results = request.r;
336-
var ids, fetch, fetchOps;
335+
var ids;
336+
var fetch;
337+
var fetchOps;
337338
if (results) {
338339
ids = [];
339340
for (var i = 0; i < results.length; i++) {
@@ -362,7 +363,6 @@ function getQueryOptions(request) {
362363

363364
Agent.prototype._queryFetch = function(queryId, collection, query, options, callback) {
364365
// Fetch the results of a query once
365-
var agent = this;
366366
this.backend.queryFetch(this, collection, query, options, function(err, results, extra) {
367367
if (err) return callback(err);
368368
var message = {
@@ -607,10 +607,10 @@ Agent.prototype._createOp = function(request) {
607607
}
608608
};
609609

610-
Agent.prototype._fetchSnapshot = function (collection, id, version, callback) {
610+
Agent.prototype._fetchSnapshot = function(collection, id, version, callback) {
611611
this.backend.fetchSnapshot(this, collection, id, version, callback);
612612
};
613613

614-
Agent.prototype._fetchSnapshotByTimestamp = function (collection, id, timestamp, callback) {
614+
Agent.prototype._fetchSnapshotByTimestamp = function(collection, id, timestamp, callback) {
615615
this.backend.fetchSnapshotByTimestamp(this, collection, id, timestamp, callback);
616616
};

0 commit comments

Comments
 (0)