Skip to content

Commit

Permalink
[pkg] Update prettier to version 2.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Jun 13, 2020
1 parent b6ae22a commit 88d0345
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 36 deletions.
1 change: 1 addition & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ arrowParens: always
endOfLine: lf
proseWrap: always
singleQuote: true
trailingComma: none
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ os:
- osx
- windows
script:
- if [ "${TRAVIS_NODE_VERSION}" == "14" ] && [ "${TRAVIS_OS_NAME}" == linux ]; then npm run lint; fi
- if [ "${TRAVIS_NODE_VERSION}" == "14" ] && [ "${TRAVIS_OS_NAME}" == linux ];
then npm run lint; fi
- npm test
after_success:
- nyc report --reporter=text-lcov | coveralls
2 changes: 1 addition & 1 deletion browser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = function() {
module.exports = function () {
throw new Error(
'ws does not work in the browser. Browser clients must use the native ' +
'WebSocket object'
Expand Down
18 changes: 9 additions & 9 deletions examples/express-session-parse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const sessionParser = session({
app.use(express.static('public'));
app.use(sessionParser);

app.post('/login', function(req, res) {
app.post('/login', function (req, res) {
//
// "Log in" user and set userId to session.
//
Expand All @@ -37,11 +37,11 @@ app.post('/login', function(req, res) {
res.send({ result: 'OK', message: 'Session updated' });
});

app.delete('/logout', function(request, response) {
app.delete('/logout', function (request, response) {
const ws = map.get(request.session.userId);

console.log('Destroying session');
request.session.destroy(function() {
request.session.destroy(function () {
if (ws) ws.close();

response.send({ result: 'OK', message: 'Session destroyed' });
Expand All @@ -54,7 +54,7 @@ app.delete('/logout', function(request, response) {
const server = http.createServer(app);
const wss = new WebSocket.Server({ clientTracking: false, noServer: true });

server.on('upgrade', function(request, socket, head) {
server.on('upgrade', function (request, socket, head) {
console.log('Parsing session from request...');

sessionParser(request, {}, () => {
Expand All @@ -65,32 +65,32 @@ server.on('upgrade', function(request, socket, head) {

console.log('Session is parsed!');

wss.handleUpgrade(request, socket, head, function(ws) {
wss.handleUpgrade(request, socket, head, function (ws) {
wss.emit('connection', ws, request);
});
});
});

wss.on('connection', function(ws, request) {
wss.on('connection', function (ws, request) {
const userId = request.session.userId;

map.set(userId, ws);

ws.on('message', function(message) {
ws.on('message', function (message) {
//
// Here we can now use session parameters.
//
console.log(`Received message ${message} from user ${userId}`);
});

ws.on('close', function() {
ws.on('close', function () {
map.delete(userId);
});
});

//
// Start the server.
//
server.listen(8080, function() {
server.listen(8080, function () {
console.log('Listening on http://localhost:8080');
});
20 changes: 10 additions & 10 deletions examples/express-session-parse/public/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function() {
(function () {
const messages = document.querySelector('#messages');
const wsButton = document.querySelector('#wsButton');
const wsSendButton = document.querySelector('#wsSendButton');
Expand All @@ -16,46 +16,46 @@
: Promise.reject(new Error('Unexpected response'));
}

login.onclick = function() {
login.onclick = function () {
fetch('/login', { method: 'POST', credentials: 'same-origin' })
.then(handleResponse)
.then(showMessage)
.catch(function(err) {
.catch(function (err) {
showMessage(err.message);
});
};

logout.onclick = function() {
logout.onclick = function () {
fetch('/logout', { method: 'DELETE', credentials: 'same-origin' })
.then(handleResponse)
.then(showMessage)
.catch(function(err) {
.catch(function (err) {
showMessage(err.message);
});
};

let ws;

wsButton.onclick = function() {
wsButton.onclick = function () {
if (ws) {
ws.onerror = ws.onopen = ws.onclose = null;
ws.close();
}

ws = new WebSocket(`ws://${location.host}`);
ws.onerror = function() {
ws.onerror = function () {
showMessage('WebSocket error');
};
ws.onopen = function() {
ws.onopen = function () {
showMessage('WebSocket connection established');
};
ws.onclose = function() {
ws.onclose = function () {
showMessage('WebSocket connection closed');
ws = null;
};
};

wsSendButton.onclick = function() {
wsSendButton.onclick = function () {
if (!ws) {
showMessage('No WebSocket connection');
return;
Expand Down
10 changes: 5 additions & 5 deletions examples/server-stats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ app.use(express.static(path.join(__dirname, '/public')));
const server = createServer(app);
const wss = new WebSocket.Server({ server });

wss.on('connection', function(ws) {
const id = setInterval(function() {
ws.send(JSON.stringify(process.memoryUsage()), function() {
wss.on('connection', function (ws) {
const id = setInterval(function () {
ws.send(JSON.stringify(process.memoryUsage()), function () {
//
// Ignore errors.
//
});
}, 100);
console.log('started client interval');

ws.on('close', function() {
ws.on('close', function () {
console.log('stopping client interval');
clearInterval(id);
});
});

server.listen(8080, function() {
server.listen(8080, function () {
console.log('Listening on http://localhost:8080');
});
8 changes: 4 additions & 4 deletions lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function createWebSocketStream(ws, options) {
duplex.push(null);
});

duplex._destroy = function(err, callback) {
duplex._destroy = function (err, callback) {
if (ws.readyState === ws.CLOSED) {
callback(err);
process.nextTick(emitClose, duplex);
Expand All @@ -110,7 +110,7 @@ function createWebSocketStream(ws, options) {
ws.terminate();
};

duplex._final = function(callback) {
duplex._final = function (callback) {
if (ws.readyState === ws.CONNECTING) {
ws.once('open', function open() {
duplex._final(callback);
Expand Down Expand Up @@ -138,14 +138,14 @@ function createWebSocketStream(ws, options) {
}
};

duplex._read = function() {
duplex._read = function () {
if (ws.readyState === ws.OPEN && !resumeOnReceiverDrain) {
resumeOnReceiverDrain = true;
if (!ws._receiver._writableState.needDrain) ws._socket.resume();
}
};

duplex._write = function(chunk, encoding, callback) {
duplex._write = function (chunk, encoding, callback) {
if (ws.readyState === ws.CONNECTING) {
ws.once('open', function open() {
duplex._write(chunk, encoding, callback);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"eslint-plugin-prettier": "^3.0.1",
"mocha": "^7.0.0",
"nyc": "^15.0.0",
"prettier": "^1.17.0",
"prettier": "^2.0.5",
"utf-8-validate": "^5.0.2"
}
}
2 changes: 1 addition & 1 deletion test/websocket-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('WebSocketServer', () => {
});
});

it('uses a precreated http server listening on unix socket', function(done) {
it('uses a precreated http server listening on unix socket', function (done) {
//
// Skip this test on Windows as it throws errors for obvious reasons.
//
Expand Down
6 changes: 2 additions & 4 deletions test/websocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('WebSocket', () => {
);
});

it('accepts `url.URL` objects as url', function(done) {
it('accepts `url.URL` objects as url', function (done) {
const agent = new CustomAgent();

agent.addRequest = (req, opts) => {
Expand Down Expand Up @@ -1345,9 +1345,7 @@ describe('WebSocket', () => {
'Invalid WebSocket frame: MASK must be set'
);
assert.ok(
Buffer.concat(chunks)
.slice(0, 2)
.equals(Buffer.from('8102', 'hex'))
Buffer.concat(chunks).slice(0, 2).equals(Buffer.from('8102', 'hex'))
);

ws.on('close', (code, reason) => {
Expand Down

0 comments on commit 88d0345

Please sign in to comment.