Skip to content

Commit

Permalink
Fix common linter errors for web-pubsub-express (#17301)
Browse files Browse the repository at this point in the history
* Run lint:fix

* Fix tsdoc/syntax errors around @param tag

* Update lint report name
  • Loading branch information
ramya-rao-a authored Aug 27, 2021
1 parent cb9de8f commit 28e6a57
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 67 deletions.
4 changes: 2 additions & 2 deletions sdk/web-pubsub/web-pubsub-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"integration-test:node": "echo skipped",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o signalr-lintReport.html || exit 0",
"lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o webpubsub-express-lintReport.html || exit 0",
"pack": "npm pack 2>&1",
"test:browser": "echo \"Browser is not supported.\" && exit 0",
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
Expand All @@ -42,7 +42,7 @@
],
"repository": "github:Azure/azure-sdk-for-js",
"keywords": [
"Azure",
"azure",
"cloud"
],
"author": "Microsoft Corporation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function getConnectResponseHandler(
connectRequest: ConnectRequest,
response: ServerResponse
): ConnectResponseHandler {
let states: Record<string, any> = connectRequest.context.states;
const states: Record<string, any> = connectRequest.context.states;
let modified = false;
const handler = {
setState(name: string, value: unknown): void {
Expand Down Expand Up @@ -62,7 +62,7 @@ function getUserEventResponseHandler(
userRequest: UserEventRequest,
response: ServerResponse
): UserEventResponseHandler {
let states: Record<string, any> = userRequest.context.states;
const states: Record<string, any> = userRequest.context.states;
let modified = false;
const handler = {
setState(name: string, value: unknown): void {
Expand Down
22 changes: 11 additions & 11 deletions sdk/web-pubsub/web-pubsub-express/src/cloudEventsProtocols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,19 @@ export interface DisconnectedRequest {
export interface ConnectResponseHandler {
/**
* Set the state of the connection
* @param name The name of the state
* @param value The value of the state
* @param name - The name of the state
* @param value - The value of the state
*/
setState(name: string, value: unknown): void;
/**
* Return success response to the service.
* @param response The response for the connect event.
* @param response - The response for the connect event.
*/
success(response?: ConnectResponse): void;
/**
* Return failed response and the service will reject the client WebSocket connection.
* @param code Code can be 400 user error, 401 unauthorized and 500 server error.
* @param detail The detail of the error.
* @param code - Code can be 400 user error, 401 unauthorized and 500 server error.
* @param detail - The detail of the error.
*/
fail(code: 400 | 401 | 500, detail?: string): void;
}
Expand All @@ -181,20 +181,20 @@ export interface ConnectResponseHandler {
export interface UserEventResponseHandler {
/**
* Set the state of the connection
* @param name The name of the state
* @param value The value of the state
* @param name - The name of the state
* @param value - The value of the state
*/
setState(name: string, value: unknown): void;
/**
* Return success response with data to be delivered to the client WebSocket connection.
* @param data The payload data to be returned to the client.
* @param dataType The type of the payload data.
* @param data - The payload data to be returned to the client.
* @param dataType - The type of the payload data.
*/
success(data?: string | ArrayBuffer, dataType?: "binary" | "text" | "json"): void;
/**
* Return failed response and the service will close the client WebSocket connection.
* @param code Code can be 400 user error, 401 unauthorized and 500 server error.
* @param detail The detail of the error.
* @param code - Code can be 400 user error, 401 unauthorized and 500 server error.
* @param detail - The detail of the error.
*/
fail(code: 400 | 401 | 500, detail?: string): void;
}
Expand Down
7 changes: 5 additions & 2 deletions sdk/web-pubsub/web-pubsub-express/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { IncomingMessage } from "http";
import { Message } from "cloudevents";

Expand All @@ -15,8 +18,8 @@ export function fromBase64JsonString(base64String: string): Record<string, any>
}

try {
let buf = Buffer.from(base64String, "base64").toString();
let parsed = JSON.parse(buf);
const buf = Buffer.from(base64String, "base64").toString();
const parsed = JSON.parse(buf);
return isJsonObject(parsed) ? parsed : {};
} catch (e) {
console.warn("Unexpected state format:" + e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export class WebPubSubEventHandler {
* });
* ```
*
* @param hub The name of the hub to listen to
* @param allowedEndpoints The allowed endpoints for the incoming CloudEvents request
* @param options Options to configure the event handler
* @param hub - The name of the hub to listen to
* @param allowedEndpoints - The allowed endpoints for the incoming CloudEvents request
* @param options - Options to configure the event handler
*/
constructor(
private hub: string,
Expand Down
32 changes: 16 additions & 16 deletions sdk/web-pubsub/web-pubsub-express/test/connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("Can handle connect event", function() {
const endSpy = sinon.spy(res.end);

const dispatcher = new CloudEventsDispatcher("hub1", ["*"]);
var result = await dispatcher.processRequest(req, res);
const result = await dispatcher.processRequest(req, res);
assert.isFalse(result);
assert.isTrue(endSpy.notCalled);
});
Expand All @@ -59,7 +59,7 @@ describe("Can handle connect event", function() {
buildRequest(req, "hub", "conn1");

const dispatcher = new CloudEventsDispatcher("hub1", ["*"]);
var result = await dispatcher.processRequest(req, res);
const result = await dispatcher.processRequest(req, res);
assert.isFalse(result);
assert.isTrue(endSpy.notCalled);
});
Expand All @@ -69,7 +69,7 @@ describe("Can handle connect event", function() {
buildRequest(req, "hub", "conn1");

const dispatcher = new CloudEventsDispatcher("hub", ["*"]);
var result = await dispatcher.processRequest(req, res);
const result = await dispatcher.processRequest(req, res);
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(401, res.statusCode, "should be 401");
Expand All @@ -80,7 +80,7 @@ describe("Can handle connect event", function() {
buildRequest(req, "hub", "conn1");

const dispatcher = new CloudEventsDispatcher("hub", ["*"], {});
var result = await dispatcher.processRequest(req, res);
const result = await dispatcher.processRequest(req, res);
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(401, res.statusCode, "should be 401");
Expand All @@ -95,9 +95,9 @@ describe("Can handle connect event", function() {
res.fail(400);
}
});
var process = dispatcher.processRequest(req, res);
const process = dispatcher.processRequest(req, res);
mockBody(req, JSON.stringify({}));
var result = await process;
const result = await process;
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(400, res.statusCode, "should be error");
Expand All @@ -112,9 +112,9 @@ describe("Can handle connect event", function() {
res.success();
}
});
var process = dispatcher.processRequest(req, res);
const process = dispatcher.processRequest(req, res);
mockBody(req, JSON.stringify({}));
var result = await process;
const result = await process;
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(200, res.statusCode, "should be success");
Expand All @@ -129,9 +129,9 @@ describe("Can handle connect event", function() {
res.success({ userId: "vic" });
}
});
var process = dispatcher.processRequest(req, res);
const process = dispatcher.processRequest(req, res);
mockBody(req, JSON.stringify({}));
var result = await process;
const result = await process;
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(200, res.statusCode, "should be success");
Expand All @@ -150,9 +150,9 @@ describe("Can handle connect event", function() {
res.success({ userId: "vic" });
}
});
var process = dispatcher.processRequest(req, res);
const process = dispatcher.processRequest(req, res);
mockBody(req, JSON.stringify({}));
var result = await process;
const result = await process;
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(
Expand Down Expand Up @@ -182,9 +182,9 @@ describe("Can handle connect event", function() {
response.success();
}
});
var process = dispatcher.processRequest(req, res);
const process = dispatcher.processRequest(req, res);
mockBody(req, JSON.stringify({}));
var result = await process;
const result = await process;
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(200, res.statusCode, "should be success");
Expand All @@ -199,9 +199,9 @@ describe("Can handle connect event", function() {
response.success();
}
});
var process = dispatcher.processRequest(req, res);
const process = dispatcher.processRequest(req, res);
mockBody(req, JSON.stringify({}));
var result = await process;
const result = await process;
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(200, res.statusCode, "should be success");
Expand Down
12 changes: 6 additions & 6 deletions sdk/web-pubsub/web-pubsub-express/test/connected.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("Can handle connected event", function() {
const endSpy = sinon.spy(res.end);

const dispatcher = new CloudEventsDispatcher("hub1", ["*"]);
var result = await dispatcher.processRequest(req, res);
const result = await dispatcher.processRequest(req, res);
assert.isFalse(result);
assert.isTrue(endSpy.notCalled);
});
Expand All @@ -56,7 +56,7 @@ describe("Can handle connected event", function() {
buildRequest(req, "hub", "conn1");

const dispatcher = new CloudEventsDispatcher("hub1", ["*"]);
var result = await dispatcher.processRequest(req, res);
const result = await dispatcher.processRequest(req, res);
assert.isFalse(result);
assert.isTrue(endSpy.notCalled);
});
Expand All @@ -66,7 +66,7 @@ describe("Can handle connected event", function() {
buildRequest(req, "hub", "conn1");

const dispatcher = new CloudEventsDispatcher("hub", ["*"]);
var result = await dispatcher.processRequest(req, res);
const result = await dispatcher.processRequest(req, res);
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(200, res.statusCode, "should be 200");
Expand All @@ -77,7 +77,7 @@ describe("Can handle connected event", function() {
buildRequest(req, "hub", "conn1");

const dispatcher = new CloudEventsDispatcher("hub", ["*"], {});
var result = await dispatcher.processRequest(req, res);
const result = await dispatcher.processRequest(req, res);
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(200, res.statusCode, "should be 200");
Expand All @@ -92,9 +92,9 @@ describe("Can handle connected event", function() {
throw new Error();
}
});
var process = dispatcher.processRequest(req, res);
const process = dispatcher.processRequest(req, res);
mockBody(req, JSON.stringify({}));
var result = await process;
const result = await process;
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(200, res.statusCode, "should be error");
Expand Down
12 changes: 6 additions & 6 deletions sdk/web-pubsub/web-pubsub-express/test/disconnected.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("Can handle disconnected event", function() {
const endSpy = sinon.spy(res.end);

const dispatcher = new CloudEventsDispatcher("hub1", ["*"]);
var result = await dispatcher.processRequest(req, res);
const result = await dispatcher.processRequest(req, res);
assert.isFalse(result);
assert.isTrue(endSpy.notCalled);
});
Expand All @@ -56,7 +56,7 @@ describe("Can handle disconnected event", function() {
buildRequest(req, "hub", "conn1");

const dispatcher = new CloudEventsDispatcher("hub1", ["*"]);
var result = await dispatcher.processRequest(req, res);
const result = await dispatcher.processRequest(req, res);
assert.isFalse(result);
assert.isTrue(endSpy.notCalled);
});
Expand All @@ -66,7 +66,7 @@ describe("Can handle disconnected event", function() {
buildRequest(req, "hub", "conn1");

const dispatcher = new CloudEventsDispatcher("hub", ["*"]);
var result = await dispatcher.processRequest(req, res);
const result = await dispatcher.processRequest(req, res);
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(200, res.statusCode, "should be 200");
Expand All @@ -77,7 +77,7 @@ describe("Can handle disconnected event", function() {
buildRequest(req, "hub", "conn1");

const dispatcher = new CloudEventsDispatcher("hub", ["*"], {});
var result = await dispatcher.processRequest(req, res);
const result = await dispatcher.processRequest(req, res);
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(200, res.statusCode, "should be 200");
Expand All @@ -92,9 +92,9 @@ describe("Can handle disconnected event", function() {
throw new Error();
}
});
var process = dispatcher.processRequest(req, res);
const process = dispatcher.processRequest(req, res);
mockBody(req, JSON.stringify({}));
var result = await process;
const result = await process;
assert.isTrue(result, "should handle");
assert.isTrue(endSpy.calledOnce, "should call once");
assert.equal(200, res.statusCode, "should be error");
Expand Down
Loading

0 comments on commit 28e6a57

Please sign in to comment.