Skip to content

Commit 886be96

Browse files
JustinBeckwithalexander-fenster
authored andcommitted
Enable prefer-const in the eslint config (#181)
1 parent e35ee20 commit 886be96

File tree

10 files changed

+102
-100
lines changed

10 files changed

+102
-100
lines changed

packages/google-cloud-node/.eslintrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ rules:
1212
eqeqeq: error
1313
no-warning-comments: warn
1414
no-var: error
15+
prefer-const: error

packages/google-cloud-node/smoke-test/speech_smoke_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ describe('SpeechSmokeTest', () => {
3838
config: config,
3939
audio: audio,
4040
};
41-
client.recognize(request)
41+
client
42+
.recognize(request)
4243
.then(responses => {
4344
const response = responses[0];
4445
console.log(response);

packages/google-cloud-node/src/helpers.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616

1717
'use strict';
1818

19-
let common = require('@google-cloud/common');
20-
let pumpify = require('pumpify');
21-
let streamEvents = require('stream-events');
22-
let through = require('through2');
19+
const common = require('@google-cloud/common');
20+
const pumpify = require('pumpify');
21+
const streamEvents = require('stream-events');
22+
const through = require('through2');
2323

2424
/*!
2525
* Return a dictionary-like object with helpers to augment the Speech
2626
* GAPIC.
2727
*/
2828
module.exports = () => {
29-
let methods = {};
29+
const methods = {};
3030

3131
/**
3232
* Performs bidirectional streaming speech recognition: receive results while
@@ -69,9 +69,9 @@ module.exports = () => {
6969
}
7070

7171
// Format the audio content as input request for pipeline
72-
let recognizeStream = streamEvents(pumpify.obj());
72+
const recognizeStream = streamEvents(pumpify.obj());
7373

74-
let requestStream = this._innerApiCalls
74+
const requestStream = this._innerApiCalls
7575
.streamingRecognize(options)
7676
.on('error', err => {
7777
recognizeStream.destroy(err);
@@ -87,7 +87,7 @@ module.exports = () => {
8787
// config) is delayed until we get the first burst of data.
8888
recognizeStream.once('writing', () => {
8989
// The first message should contain the streaming config.
90-
let firstMessage = true;
90+
const firstMessage = true;
9191

9292
// Set up appropriate piping between the stream returned by
9393
// the underlying API method and the one that we return.
@@ -96,7 +96,7 @@ module.exports = () => {
9696
// This entails that the user sends raw audio; it is wrapped in
9797
// the appropriate request structure.
9898
through.obj((obj, _, next) => {
99-
let payload = {};
99+
const payload = {};
100100
if (firstMessage && config !== undefined) {
101101
// Write the initial configuration to the stream.
102102
payload.streamingConfig = config;

packages/google-cloud-node/src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ const gapic = Object.freeze({
4848
});
4949

5050
// Augment the SpeechClient objects with the helpers.
51-
for (let gapicVersion of Object.keys(gapic)) {
52-
let clientProto = gapic[gapicVersion].SpeechClient.prototype;
51+
for (const gapicVersion of Object.keys(gapic)) {
52+
const clientProto = gapic[gapicVersion].SpeechClient.prototype;
5353
Object.assign(clientProto, helpers());
5454
}
5555

packages/google-cloud-node/src/v1/speech_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class SpeechClient {
166166
'longRunningRecognize',
167167
'streamingRecognize',
168168
];
169-
for (let methodName of speechStubMethods) {
169+
for (const methodName of speechStubMethods) {
170170
this._innerApiCalls[methodName] = gax.createApiCall(
171171
speechStub.then(
172172
stub =>

packages/google-cloud-node/src/v1p1beta1/speech_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class SpeechClient {
166166
'longRunningRecognize',
167167
'streamingRecognize',
168168
];
169-
for (let methodName of speechStubMethods) {
169+
for (const methodName of speechStubMethods) {
170170
this._innerApiCalls[methodName] = gax.createApiCall(
171171
speechStub.then(
172172
stub =>

packages/google-cloud-node/system-test/speech_smoke_test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,30 @@ describe('SpeechSmokeTest', () => {
1818
it('successfully makes a call to the service', done => {
1919
const speech = require('../src');
2020

21-
let client = new speech.v1.SpeechClient({
21+
const client = new speech.v1.SpeechClient({
2222
// optional auth parameters.
2323
});
2424

25-
let languageCode = 'en-US';
26-
let sampleRateHertz = 44100;
27-
let encoding = 'FLAC';
28-
let config = {
25+
const languageCode = 'en-US';
26+
const sampleRateHertz = 44100;
27+
const encoding = 'FLAC';
28+
const config = {
2929
languageCode: languageCode,
3030
sampleRateHertz: sampleRateHertz,
3131
encoding: encoding,
3232
};
33-
let uri = 'gs://gapic-toolkit/hello.flac';
34-
let audio = {
33+
const uri = 'gs://gapic-toolkit/hello.flac';
34+
const audio = {
3535
uri: uri,
3636
};
37-
let request = {
37+
const request = {
3838
config: config,
3939
audio: audio,
4040
};
4141
client
4242
.recognize(request)
4343
.then(responses => {
44-
let response = responses[0];
44+
const response = responses[0];
4545
console.log(response);
4646
})
4747
.then(done)

packages/google-cloud-node/system-test/speech_smoke_test_v1p1beta1.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,30 @@ describe('SpeechSmokeTest v1p1beta1', () => {
1818
it('successfully makes a call to the service', done => {
1919
const speech = require('../src');
2020

21-
let client = new speech.v1p1beta1.SpeechClient({
21+
const client = new speech.v1p1beta1.SpeechClient({
2222
// optional auth parameters.
2323
});
2424

25-
let languageCode = 'en-US';
26-
let sampleRateHertz = 44100;
27-
let encoding = 'FLAC';
28-
let config = {
25+
const languageCode = 'en-US';
26+
const sampleRateHertz = 44100;
27+
const encoding = 'FLAC';
28+
const config = {
2929
languageCode: languageCode,
3030
sampleRateHertz: sampleRateHertz,
3131
encoding: encoding,
3232
};
33-
let uri = 'gs://gapic-toolkit/hello.flac';
34-
let audio = {
33+
const uri = 'gs://gapic-toolkit/hello.flac';
34+
const audio = {
3535
uri: uri,
3636
};
37-
let request = {
37+
const request = {
3838
config: config,
3939
audio: audio,
4040
};
4141
client
4242
.recognize(request)
4343
.then(responses => {
44-
let response = responses[0];
44+
const response = responses[0];
4545
console.log(response);
4646
})
4747
.then(done)

packages/google-cloud-node/test/gapic-v1.test.js

+40-40
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,38 @@ const assert = require('assert');
1818

1919
const speechModule = require('../src');
2020

21-
let FAKE_STATUS_CODE = 1;
22-
let error = new Error();
21+
const FAKE_STATUS_CODE = 1;
22+
const error = new Error();
2323
error.code = FAKE_STATUS_CODE;
2424

2525
describe('SpeechClient', () => {
2626
describe('recognize', () => {
2727
it('invokes recognize without error', done => {
28-
let client = new speechModule.v1.SpeechClient({
28+
const client = new speechModule.v1.SpeechClient({
2929
credentials: {client_email: 'bogus', private_key: 'bogus'},
3030
projectId: 'bogus',
3131
});
3232

3333
// Mock request
34-
let encoding = 'FLAC';
35-
let sampleRateHertz = 44100;
36-
let languageCode = 'en-US';
37-
let config = {
34+
const encoding = 'FLAC';
35+
const sampleRateHertz = 44100;
36+
const languageCode = 'en-US';
37+
const config = {
3838
encoding: encoding,
3939
sampleRateHertz: sampleRateHertz,
4040
languageCode: languageCode,
4141
};
42-
let uri = 'gs://bucket_name/file_name.flac';
43-
let audio = {
42+
const uri = 'gs://bucket_name/file_name.flac';
43+
const audio = {
4444
uri: uri,
4545
};
46-
let request = {
46+
const request = {
4747
config: config,
4848
audio: audio,
4949
};
5050

5151
// Mock response
52-
let expectedResponse = {};
52+
const expectedResponse = {};
5353

5454
// Mock Grpc layer
5555
client._innerApiCalls.recognize = mockSimpleGrpcMethod(
@@ -65,25 +65,25 @@ describe('SpeechClient', () => {
6565
});
6666

6767
it('invokes recognize with error', done => {
68-
let client = new speechModule.v1.SpeechClient({
68+
const client = new speechModule.v1.SpeechClient({
6969
credentials: {client_email: 'bogus', private_key: 'bogus'},
7070
projectId: 'bogus',
7171
});
7272

7373
// Mock request
74-
let encoding = 'FLAC';
75-
let sampleRateHertz = 44100;
76-
let languageCode = 'en-US';
77-
let config = {
74+
const encoding = 'FLAC';
75+
const sampleRateHertz = 44100;
76+
const languageCode = 'en-US';
77+
const config = {
7878
encoding: encoding,
7979
sampleRateHertz: sampleRateHertz,
8080
languageCode: languageCode,
8181
};
82-
let uri = 'gs://bucket_name/file_name.flac';
83-
let audio = {
82+
const uri = 'gs://bucket_name/file_name.flac';
83+
const audio = {
8484
uri: uri,
8585
};
86-
let request = {
86+
const request = {
8787
config: config,
8888
audio: audio,
8989
};
@@ -106,31 +106,31 @@ describe('SpeechClient', () => {
106106

107107
describe('longRunningRecognize', function() {
108108
it('invokes longRunningRecognize without error', done => {
109-
let client = new speechModule.v1.SpeechClient({
109+
const client = new speechModule.v1.SpeechClient({
110110
credentials: {client_email: 'bogus', private_key: 'bogus'},
111111
projectId: 'bogus',
112112
});
113113

114114
// Mock request
115-
let encoding = 'FLAC';
116-
let sampleRateHertz = 44100;
117-
let languageCode = 'en-US';
118-
let config = {
115+
const encoding = 'FLAC';
116+
const sampleRateHertz = 44100;
117+
const languageCode = 'en-US';
118+
const config = {
119119
encoding: encoding,
120120
sampleRateHertz: sampleRateHertz,
121121
languageCode: languageCode,
122122
};
123-
let uri = 'gs://bucket_name/file_name.flac';
124-
let audio = {
123+
const uri = 'gs://bucket_name/file_name.flac';
124+
const audio = {
125125
uri: uri,
126126
};
127-
let request = {
127+
const request = {
128128
config: config,
129129
audio: audio,
130130
};
131131

132132
// Mock response
133-
let expectedResponse = {};
133+
const expectedResponse = {};
134134

135135
// Mock Grpc layer
136136
client._innerApiCalls.longRunningRecognize = mockLongRunningGrpcMethod(
@@ -141,7 +141,7 @@ describe('SpeechClient', () => {
141141
client
142142
.longRunningRecognize(request)
143143
.then(responses => {
144-
let operation = responses[0];
144+
const operation = responses[0];
145145
return operation.promise();
146146
})
147147
.then(responses => {
@@ -154,25 +154,25 @@ describe('SpeechClient', () => {
154154
});
155155

156156
it('invokes longRunningRecognize with error', done => {
157-
let client = new speechModule.v1.SpeechClient({
157+
const client = new speechModule.v1.SpeechClient({
158158
credentials: {client_email: 'bogus', private_key: 'bogus'},
159159
projectId: 'bogus',
160160
});
161161

162162
// Mock request
163-
let encoding = 'FLAC';
164-
let sampleRateHertz = 44100;
165-
let languageCode = 'en-US';
166-
let config = {
163+
const encoding = 'FLAC';
164+
const sampleRateHertz = 44100;
165+
const languageCode = 'en-US';
166+
const config = {
167167
encoding: encoding,
168168
sampleRateHertz: sampleRateHertz,
169169
languageCode: languageCode,
170170
};
171-
let uri = 'gs://bucket_name/file_name.flac';
172-
let audio = {
171+
const uri = 'gs://bucket_name/file_name.flac';
172+
const audio = {
173173
uri: uri,
174174
};
175-
let request = {
175+
const request = {
176176
config: config,
177177
audio: audio,
178178
};
@@ -187,7 +187,7 @@ describe('SpeechClient', () => {
187187
client
188188
.longRunningRecognize(request)
189189
.then(responses => {
190-
let operation = responses[0];
190+
const operation = responses[0];
191191
return operation.promise();
192192
})
193193
.then(() => {
@@ -201,7 +201,7 @@ describe('SpeechClient', () => {
201201
});
202202

203203
it('has longrunning decoder functions', () => {
204-
let client = new speechModule.v1.SpeechClient({
204+
const client = new speechModule.v1.SpeechClient({
205205
credentials: {client_email: 'bogus', private_key: 'bogus'},
206206
projectId: 'bogus',
207207
});
@@ -233,7 +233,7 @@ function mockSimpleGrpcMethod(expectedRequest, response, error) {
233233
function mockLongRunningGrpcMethod(expectedRequest, response, error) {
234234
return request => {
235235
assert.deepStrictEqual(request, expectedRequest);
236-
let mockOperation = {
236+
const mockOperation = {
237237
promise: function() {
238238
return new Promise((resolve, reject) => {
239239
if (error) {

0 commit comments

Comments
 (0)