Skip to content

Commit ef7c7ed

Browse files
chore: replace var with const or let (#36)
1 parent a9949dc commit ef7c7ed

18 files changed

Lines changed: 82 additions & 82 deletions

File tree

handwritten/nodejs-error-reporting/src/build-stack-trace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ const SRC_ROOT = __dirname;
2626
* where this method was invoked.
2727
*/
2828
export function buildStackTrace(message: string) {
29-
var target = {};
29+
const target = {};
3030
// Build a stack trace without the frames associated with `buildStackTrace`.
3131
// The stack is located at `target.stack`.
3232
Error.captureStackTrace(target, buildStackTrace);
33-
var prefix = message ? message + '\n' : '';
33+
const prefix = message ? message + '\n' : '';
3434
return (
3535
prefix +
3636
(target as any).stack

handwritten/nodejs-error-reporting/src/classes/error-message.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616

1717
import * as is from 'is';
18-
var isString = is.string;
19-
var isNumber = is.number;
20-
var isObject = is.object;
18+
const isString = is.string;
19+
const isNumber = is.number;
20+
const isObject = is.object;
2121

2222
import {RequestInformationContainer} from './request-information-container';
2323
import {ServiceContext} from '../configuration';

handwritten/nodejs-error-reporting/src/classes/request-information-container.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616

1717
import * as is from 'is';
18-
var isString = is.string;
19-
var isNumber = is.number;
18+
const isString = is.string;
19+
const isNumber = is.number;
2020

2121
export class RequestInformationContainer {
2222
url: string;

handwritten/nodejs-error-reporting/src/configuration.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
var env = process.env;
17+
const env = process.env;
1818
import has = require('lodash.has');
1919
import * as is from 'is';
20-
var isObject = is.object;
21-
var isBoolean = is.boolean;
22-
var isString = is.string;
23-
var isNumber = is.number;
20+
const isObject = is.object;
21+
const isBoolean = is.boolean;
22+
const isString = is.string;
23+
const isNumber = is.number;
2424

2525
import {Logger} from '@google-cloud/common';
2626

@@ -220,8 +220,8 @@ export class Configuration {
220220
// Otherwise, the value of the environment variable GAE_MODULE_VERSION
221221
// will be used if and only if the FUNCTION_NAME environment variable is
222222
// not set.
223-
var service;
224-
var version;
223+
let service;
224+
let version;
225225

226226
if (env.FUNCTION_NAME) {
227227
service = env.FUNCTION_NAME;

handwritten/nodejs-error-reporting/src/google-apis/auth-client.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ import * as common from '@google-cloud/common';
1919
const pkg = require('../../../package.json');
2020
import * as is from 'is';
2121
// TODO: Address the error where `is` does not have a `fn` property
22-
var isFunction = (is as {} as {fn: Function}).fn;
23-
var isString = is.string;
22+
const isFunction = (is as {} as {fn: Function}).fn;
23+
const isString = is.string;
2424

2525
import {Configuration} from '../configuration';
2626
import {ErrorMessage} from '../classes/error-message';
2727
import * as http from 'http';
2828

2929
/* @const {Array<String>} list of scopes needed to work with the errors api. */
30-
var SCOPES = ['https://www.googleapis.com/auth/cloud-platform'];
30+
const SCOPES = ['https://www.googleapis.com/auth/cloud-platform'];
3131

3232
/* @const {String} Base Error Reporting API */
33-
var API = 'https://clouderrorreporting.googleapis.com/v1beta1';
33+
const API = 'https://clouderrorreporting.googleapis.com/v1beta1';
3434

3535
/**
3636
* The RequestHandler constructor initializes several properties on the
@@ -96,9 +96,9 @@ export class RequestHandler extends common.Service {
9696
* @param {Logger} logger - an instance of logger
9797
*/
9898
constructor(config: Configuration, logger: common.Logger) {
99-
var pid = config.getProjectId();
99+
const pid = config.getProjectId();
100100
// If an API key is provided, do not try to authenticate.
101-
var tryAuthenticate = !config.getKey();
101+
const tryAuthenticate = !config.getKey();
102102
super(
103103
{
104104
packageJson: pkg,
@@ -114,7 +114,7 @@ export class RequestHandler extends common.Service {
114114
this._config = config;
115115
this._logger = logger;
116116

117-
var that = this;
117+
const that = this;
118118
if (tryAuthenticate) {
119119
this.authClient.getToken(function(err: Error) {
120120
if (err) {
@@ -167,7 +167,7 @@ export class RequestHandler extends common.Service {
167167
* @instance
168168
*/
169169
sendError(errorMessage: ErrorMessage, userCb?: (err: Error|null, response: http.ServerResponse|null, body: any) => void) {
170-
var cb: Function = (isFunction(userCb) ? userCb : RequestHandler.noOp)!;
170+
const cb: Function = (isFunction(userCb) ? userCb : RequestHandler.noOp)!;
171171
if (this._config.getShouldReportErrorsToAPI()) {
172172
this.request(
173173
{

handwritten/nodejs-error-reporting/src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class Errors {
117117
this._client = new AuthClient(this._config, this._logger);
118118

119119
if (this._config.getReportUnhandledRejections()) {
120-
var that = this;
120+
const that = this;
121121
process.on('unhandledRejection', function(reason) {
122122
that._logger.warn(
123123
'UnhandledPromiseRejectionWarning: ' +
@@ -144,7 +144,7 @@ export class Errors {
144144
* @example
145145
* // Use to create and report errors manually with a high-degree
146146
* // of manual control
147-
* var err = errors.event()
147+
* const err = errors.event()
148148
* .setMessage('My error message')
149149
* .setUser('root@nexus');
150150
* errors.report(err, function () {
@@ -155,8 +155,8 @@ export class Errors {
155155

156156
/**
157157
* @example
158-
* var hapi = require('hapi');
159-
* var server = new hapi.Server();
158+
* const hapi = require('hapi');
159+
* const server = new hapi.Server();
160160
* server.connection({ port: 3000 });
161161
* server.start();
162162
* // AFTER ALL OTHER ROUTE HANDLERS
@@ -166,8 +166,8 @@ export class Errors {
166166

167167
/**
168168
* @example
169-
* var express = require('express');
170-
* var app = express();
169+
* const express = require('express');
170+
* const app = express();
171171
* // AFTER ALL OTHER ROUTE HANDLERS
172172
* app.use(errors.express);
173173
* app.listen(3000);
@@ -176,17 +176,17 @@ export class Errors {
176176

177177
/**
178178
* @example
179-
* var restify = require('restify');
180-
* var server = restify.createServer();
179+
* const restify = require('restify');
180+
* const server = restify.createServer();
181181
* // BEFORE ALL OTHER ROUTE HANDLERS
182182
* server.use(errors.restify(server));
183183
*/
184184
this.restify = restify(this._client, this._config);
185185

186186
/**
187187
* @example
188-
* var koa = require('koa');
189-
* var app = koa();
188+
* const koa = require('koa');
189+
* const app = koa();
190190
* // BEFORE ALL OTHER ROUTE HANDLERS HANDLERS
191191
* app.use(errors.koa);
192192
*/

handwritten/nodejs-error-reporting/src/interfaces/express.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616

1717
import * as is from 'is';
18-
var isObject = is.object;
18+
const isObject = is.object;
1919
// TODO: Address the error where `is` does not have a `fn` property
20-
var isFunction = (is as {} as {fn: Function}).fn;
20+
const isFunction = (is as {} as {fn: Function}).fn;
2121
import {ErrorMessage} from '../classes/error-message';
2222
import {expressRequestInformationExtractor} from '../request-extractors/express';
2323
import {populateErrorMessage} from '../populate-error-message';
@@ -48,15 +48,15 @@ export function makeExpressHandler(client: RequestHandler, config: Configuration
4848
* @returns {ErrorMessage} - Returns the ErrorMessage instance
4949
*/
5050
function expressErrorHandler(err: {}, req: express.Request, res: express.Response, next: Function) {
51-
var ctxService = '';
52-
var ctxVersion: string|undefined = '';
51+
let ctxService = '';
52+
let ctxVersion: string|undefined = '';
5353

5454
if (isObject(config)) {
5555
ctxService = config.getServiceContext().service;
5656
ctxVersion = config.getServiceContext().version;
5757
}
5858

59-
var em = new ErrorMessage()
59+
const em = new ErrorMessage()
6060
.consumeRequestInformation(expressRequestInformationExtractor(req, res))
6161
.setServiceContext(ctxService, ctxVersion);
6262

handwritten/nodejs-error-reporting/src/interfaces/hapi.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*/
1616

1717
import * as is from 'is';
18-
var isObject = is.object;
18+
const isObject = is.object;
1919
// TODO: Address the error where `is` does not have a `fn` property
20-
var isFunction = (is as {} as {fn: Function}).fn;
20+
const isFunction = (is as {} as {fn: Function}).fn;
2121
import {ErrorMessage} from '../classes/error-message';
2222
import {hapiRequestInformationExtractor} from '../request-extractors/hapi';
2323
import {populateErrorMessage} from '../populate-error-message';
24-
var packageJson = require('../../../package.json');
24+
const packageJson = require('../../../package.json');
2525

2626
import {RequestHandler} from '../google-apis/auth-client';
2727
import {Configuration} from '../configuration';
@@ -38,15 +38,15 @@ import * as hapi from 'hapi';
3838
* ErrorMessage
3939
*/
4040
function hapiErrorHandler(req: hapi.Request, err: {}, config: Configuration) {
41-
var service = '';
42-
var version: string|undefined = '';
41+
let service = '';
42+
let version: string|undefined = '';
4343

4444
if (isObject(config)) {
4545
service = config.getServiceContext().service;
4646
version = config.getServiceContext().version;
4747
}
4848

49-
var em = new ErrorMessage()
49+
const em = new ErrorMessage()
5050
.consumeRequestInformation(hapiRequestInformationExtractor(req))
5151
.setServiceContext(service, version);
5252

@@ -93,7 +93,7 @@ export function makeHapiPlugin(client: RequestHandler, config: Configuration) {
9393
// TODO: Handle the case when `request.response` is null
9494
request.response!.isBoom
9595
) {
96-
var em = hapiErrorHandler(
96+
const em = hapiErrorHandler(
9797
request,
9898
// TODO: Handle the case when `request.response` is null
9999
// TODO: Handle the type conflict that requires a cast to string
@@ -115,7 +115,7 @@ export function makeHapiPlugin(client: RequestHandler, config: Configuration) {
115115
}
116116
}
117117

118-
var hapiPlugin = {register: hapiRegisterFunction};
118+
const hapiPlugin = {register: hapiRegisterFunction};
119119

120120
(hapiPlugin.register as any).attributes = {
121121
name: packageJson.name,

handwritten/nodejs-error-reporting/src/interfaces/koa.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export function koaErrorHandler(client: RequestHandler, config: Configuration) {
4242
* @returns {Undefined} does not return anything
4343
*/
4444
return function*(this: {request: Request; response: Response;}, next: Function) {
45-
var svc = config.getServiceContext();
45+
const svc = config.getServiceContext();
4646

4747
try {
4848
yield next;
4949
} catch (err) {
50-
var em = new ErrorMessage()
50+
const em = new ErrorMessage()
5151
.consumeRequestInformation(
5252
koaRequestInformationExtractor(this.request, this.response)
5353
)

handwritten/nodejs-error-reporting/src/interfaces/manual.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616

1717
import * as is from 'is';
18-
var isString = is.string;
19-
var isObject = is.object;
18+
const isString = is.string;
19+
const isObject = is.object;
2020
// TODO: Address the error where `is` does not have a `fn` property
21-
var isFunction = (is as {} as {fn: Function}).fn;
21+
const isFunction = (is as {} as {fn: Function}).fn;
2222
import {ErrorMessage} from '../classes/error-message';
2323
import {manualRequestInformationExtractor} from '../request-extractors/manual';
2424
import {populateErrorMessage} from '../populate-error-message';
@@ -63,7 +63,7 @@ export function handlerSetup(client: RequestHandler, config: Configuration, logg
6363
* the parameters given.
6464
*/
6565
function reportManualError(err: {}, request?: Request, additionalMessage?: string|{}, callback?: Callback|{}|string) {
66-
var em;
66+
let em;
6767
if (isString(request)) {
6868
// no request given
6969
callback = additionalMessage;

0 commit comments

Comments
 (0)