Skip to content

Commit

Permalink
Merge pull request #302 from share/eslint
Browse files Browse the repository at this point in the history
Linter fixes
  • Loading branch information
nateps committed Jul 17, 2019
2 parents 0b65164 + 40abc17 commit 9851465
Show file tree
Hide file tree
Showing 48 changed files with 2,957 additions and 2,751 deletions.
47 changes: 47 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// The ESLint ecmaVersion argument is inconsistently used. Some rules will ignore it entirely, so if the rule has
// been set, it will still error even if it's not applicable to that version number. Since Google sets these
// rules, we have to turn them off ourselves.
const DISABLED_ES6_OPTIONS = {
'no-var': 'off',
'prefer-rest-params': 'off'
};

const SHAREDB_RULES = {
// Comma dangle is not supported in ES3
'comma-dangle': ['error', 'never'],
// We control our own objects and prototypes, so no need for this check
'guard-for-in': 'off',
// Google prescribes different indents for different cases. Let's just use 2 spaces everywhere. Note that we have
// to override ESLint's default of 0 indents for this.
'indent': ['error', 2, {
'SwitchCase': 1
}],
// Less aggressive line length than Google, which is especially useful when we have a lot of callbacks in our code
'max-len': ['error',
{
code: 120,
tabWidth: 2,
ignoreUrls: true,
}
],
// Google overrides the default ESLint behaviour here, which is slightly better for catching erroneously unused variables
'no-unused-vars': ['error', {vars: 'all', args: 'after-used'}],
// It's more readable to ensure we only have one statement per line
'max-statements-per-line': ['error', {max: 1}],
// as-needed quote props are easier to write
'quote-props': ['error', 'as-needed'],
'require-jsdoc': 'off',
'valid-jsdoc': 'off'
};

module.exports = {
extends: 'google',
parserOptions: {
ecmaVersion: 3
},
rules: Object.assign(
{},
DISABLED_ES6_OPTIONS,
SHAREDB_RULES
),
};
18 changes: 0 additions & 18 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ node_js:
- "10"
- "8"
- "6"
script: "npm run jshint && npm run test-cover"
script: "npm run lint && npm run test-cover"
# Send coverage data to Coveralls
after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
2 changes: 1 addition & 1 deletion examples/counter/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function startServer() {

// Connect any incoming WebSocket connection to ShareDB
var wss = new WebSocket.Server({server: server});
wss.on('connection', function(ws, req) {
wss.on('connection', function(ws) {
var stream = new WebSocketJSONStream(ws);
backend.listen(stream);
});
Expand Down
21 changes: 11 additions & 10 deletions examples/leaderboard/server/index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
var http = require("http");
var ShareDB = require("sharedb");
var connect = require("connect");
var http = require('http');
var ShareDB = require('sharedb');
var connect = require('connect');
var serveStatic = require('serve-static');
var ShareDBMingoMemory = require('sharedb-mingo-memory');
var WebSocketJSONStream = require('@teamwork/websocket-json-stream');
var WebSocket = require('ws');
var util = require('util');

// Start ShareDB
var share = ShareDB({db: new ShareDBMingoMemory()});
var share = new ShareDB({db: new ShareDBMingoMemory()});

// Create a WebSocket server
var app = connect();
app.use(serveStatic('.'));
var server = http.createServer(app);
var wss = new WebSocket.Server({server: server});
server.listen(8080);
console.log("Listening on http://localhost:8080");
console.log('Listening on http://localhost:8080');

// Connect any incoming WebSocket connection with ShareDB
wss.on('connection', function(ws, req) {
wss.on('connection', function(ws) {
var stream = new WebSocketJSONStream(ws);
share.listen(stream);
});

// Create initial documents
var connection = share.connect();
connection.createFetchQuery('players', {}, {}, function(err, results) {
if (err) { throw err; }
if (err) {
throw err;
}

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

names.forEach(function(name, index) {
var doc = connection.get('players', ''+index);
Expand Down
2 changes: 1 addition & 1 deletion examples/rich-text/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function startServer() {

// Connect any incoming WebSocket connection to ShareDB
var wss = new WebSocket.Server({server: server});
wss.on('connection', function(ws, req) {
wss.on('connection', function(ws) {
var stream = new WebSocketJSONStream(ws);
backend.listen(stream);
});
Expand Down
26 changes: 13 additions & 13 deletions examples/textarea/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ var sharedb = require('sharedb/lib/client');
var StringBinding = require('sharedb-string-binding');

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

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

element.style.backgroundColor = "gray";
socket.onopen = function(){
statusSpan.innerHTML = "Connected"
element.style.backgroundColor = "white";
element.style.backgroundColor = 'gray';
socket.onopen = function() {
statusSpan.innerHTML = 'Connected';
element.style.backgroundColor = 'white';
};

socket.onclose = function(){
statusSpan.innerHTML = "Closed"
element.style.backgroundColor = "gray";
socket.onclose = function() {
statusSpan.innerHTML = 'Closed';
element.style.backgroundColor = 'gray';
};

socket.onerror = function() {
statusSpan.innerHTML = "Error"
element.style.backgroundColor = "red";
}
statusSpan.innerHTML = 'Error';
element.style.backgroundColor = 'red';
};

// Create local Doc instance mapped to 'examples' collection document with id 'textarea'
var doc = connection.get('examples', 'textarea');
doc.subscribe(function(err) {
if (err) throw err;

var binding = new StringBinding(element, doc, ['content']);
binding.setup();
});
4 changes: 2 additions & 2 deletions examples/textarea/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function createDoc(callback) {
doc.fetch(function(err) {
if (err) throw err;
if (doc.type === null) {
doc.create({ content: '' }, callback);
doc.create({content: ''}, callback);
return;
}
callback();
Expand All @@ -29,7 +29,7 @@ function startServer() {

// Connect any incoming WebSocket connection to ShareDB
var wss = new WebSocket.Server({server: server});
wss.on('connection', function(ws, req) {
wss.on('connection', function(ws) {
var stream = new WebSocketJSONStream(ws);
backend.listen(stream);
});
Expand Down
12 changes: 6 additions & 6 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Agent.prototype.close = function(err) {
};

Agent.prototype._cleanup = function() {

// Only clean up once if the stream emits both 'end' and 'close'.
if (this.closed) return;

Expand Down Expand Up @@ -265,7 +264,7 @@ Agent.prototype._open = function() {
agent._handleMessage(request.data, callback);
});
});

var cleanup = agent._cleanup.bind(agent);
this.stream.on('end', cleanup);
this.stream.on('close', cleanup);
Expand Down Expand Up @@ -333,7 +332,9 @@ Agent.prototype._handleMessage = function(request, callback) {
};
function getQueryOptions(request) {
var results = request.r;
var ids, fetch, fetchOps;
var ids;
var fetch;
var fetchOps;
if (results) {
ids = [];
for (var i = 0; i < results.length; i++) {
Expand Down Expand Up @@ -362,7 +363,6 @@ function getQueryOptions(request) {

Agent.prototype._queryFetch = function(queryId, collection, query, options, callback) {
// Fetch the results of a query once
var agent = this;
this.backend.queryFetch(this, collection, query, options, function(err, results, extra) {
if (err) return callback(err);
var message = {
Expand Down Expand Up @@ -607,10 +607,10 @@ Agent.prototype._createOp = function(request) {
}
};

Agent.prototype._fetchSnapshot = function (collection, id, version, callback) {
Agent.prototype._fetchSnapshot = function(collection, id, version, callback) {
this.backend.fetchSnapshot(this, collection, id, version, callback);
};

Agent.prototype._fetchSnapshotByTimestamp = function (collection, id, timestamp, callback) {
Agent.prototype._fetchSnapshotByTimestamp = function(collection, id, timestamp, callback) {
this.backend.fetchSnapshotByTimestamp(this, collection, id, timestamp, callback);
};

0 comments on commit 9851465

Please sign in to comment.