Skip to content

Commit d4daf48

Browse files
JustinBeckwithalexander-fenster
authored andcommitted
Enable prefer-const in the eslint config (#201)
1 parent c0025c4 commit d4daf48

14 files changed

+100
-97
lines changed

packages/google-cloud-vision/.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-vision/smoke-test/image_annotator_smoke_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ describe('ImageAnnotatorSmokeTest', () => {
3939
features: features,
4040
};
4141
const requests = [requestsElement];
42-
client.batchAnnotateImages({requests: requests})
42+
client
43+
.batchAnnotateImages({requests: requests})
4344
.then(responses => {
4445
const response = responses[0];
4546
console.log(response);

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const gax = require('google-gax');
3333
*
3434
* @returns An object representing an AnnotateImageRequest.
3535
*/
36-
let _requestToObject = request => {
36+
const _requestToObject = request => {
3737
if (is.string(request)) {
3838
// Is this a URL or a local file?
3939
// Guess based on what the string looks like, and build the full
@@ -62,7 +62,7 @@ let _requestToObject = request => {
6262
* function.
6363
* @param {function} callback The callback to run.
6464
*/
65-
let _coerceRequest = (request, callback) => {
65+
const _coerceRequest = (request, callback) => {
6666
// At this point, request must be an object with an `image` key; if not,
6767
// it is an error. If there is no image, throw an exception.
6868
if (!is.object(request) || is.undefined(request.image)) {
@@ -102,7 +102,7 @@ let _coerceRequest = (request, callback) => {
102102
* @returns {function} The function that, when called, will call annotateImage
103103
* asking for the single feature annotation.
104104
*/
105-
let _createSingleFeatureMethod = featureValue => {
105+
const _createSingleFeatureMethod = featureValue => {
106106
return function(annotateImageRequest, callOptions, callback) {
107107
// Sanity check: If we got a string or buffer, we need this to be
108108
// in object form now, so we can tack on the features list.
@@ -128,7 +128,7 @@ let _createSingleFeatureMethod = featureValue => {
128128

129129
// If the user submitted explicit features that do not line up with
130130
// the precise method called, throw an exception.
131-
for (let feature of annotateImageRequest.features) {
131+
for (const feature of annotateImageRequest.features) {
132132
if (feature.type !== featureValue) {
133133
throw new Error(
134134
'Setting explicit features is not supported on this method. ' +
@@ -152,7 +152,7 @@ let _createSingleFeatureMethod = featureValue => {
152152
* onto the pure GAPIC.
153153
*/
154154
module.exports = apiVersion => {
155-
let methods = {};
155+
const methods = {};
156156

157157
/**
158158
* Annotate a single image with the requested features.
@@ -227,7 +227,7 @@ module.exports = apiVersion => {
227227
}
228228

229229
// Call the GAPIC batch annotation function.
230-
let requests = {requests: [req]};
230+
const requests = {requests: [req]};
231231
return this.batchAnnotateImages(requests, callOptions, (err, r) => {
232232
// If there is an error, handle it.
233233
if (err) {
@@ -236,7 +236,7 @@ module.exports = apiVersion => {
236236

237237
// We are guaranteed to only have one response element, since we
238238
// only sent one image.
239-
let response = r.responses[0];
239+
const response = r.responses[0];
240240

241241
// Fire the callback if applicable.
242242
return callback(undefined, response);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ const gapic = Object.freeze({
5050
});
5151

5252
// Augment the SpeechClient objects with the helpers.
53-
for (let gapicVersion of Object.keys(gapic)) {
54-
let clientProto = gapic[gapicVersion].ImageAnnotatorClient.prototype;
53+
for (const gapicVersion of Object.keys(gapic)) {
54+
const clientProto = gapic[gapicVersion].ImageAnnotatorClient.prototype;
5555
Object.assign(clientProto, helpers(gapicVersion));
5656
}
5757

packages/google-cloud-vision/src/v1/image_annotator_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class ImageAnnotatorClient {
163163
'batchAnnotateImages',
164164
'asyncBatchAnnotateFiles',
165165
];
166-
for (let methodName of imageAnnotatorStubMethods) {
166+
for (const methodName of imageAnnotatorStubMethods) {
167167
this._innerApiCalls[methodName] = gax.createApiCall(
168168
imageAnnotatorStub.then(
169169
stub =>

packages/google-cloud-vision/src/v1p1beta1/image_annotator_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class ImageAnnotatorClient {
121121
// Iterate over each of the methods that the service provides
122122
// and create an API call method for each.
123123
const imageAnnotatorStubMethods = ['batchAnnotateImages'];
124-
for (let methodName of imageAnnotatorStubMethods) {
124+
for (const methodName of imageAnnotatorStubMethods) {
125125
this._innerApiCalls[methodName] = gax.createApiCall(
126126
imageAnnotatorStub.then(
127127
stub =>

packages/google-cloud-vision/src/v1p2beta1/image_annotator_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class ImageAnnotatorClient {
163163
'batchAnnotateImages',
164164
'asyncBatchAnnotateFiles',
165165
];
166-
for (let methodName of imageAnnotatorStubMethods) {
166+
for (const methodName of imageAnnotatorStubMethods) {
167167
this._innerApiCalls[methodName] = gax.createApiCall(
168168
imageAnnotatorStub.then(
169169
stub =>

packages/google-cloud-vision/src/v1p3beta1/image_annotator_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class ImageAnnotatorClient {
163163
'batchAnnotateImages',
164164
'asyncBatchAnnotateFiles',
165165
];
166-
for (let methodName of imageAnnotatorStubMethods) {
166+
for (const methodName of imageAnnotatorStubMethods) {
167167
this._innerApiCalls[methodName] = gax.createApiCall(
168168
imageAnnotatorStub.then(
169169
stub =>

packages/google-cloud-vision/src/v1p3beta1/product_search_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class ProductSearchClient {
230230
'listProductsInProductSet',
231231
'importProductSets',
232232
];
233-
for (let methodName of productSearchStubMethods) {
233+
for (const methodName of productSearchStubMethods) {
234234
this._innerApiCalls[methodName] = gax.createApiCall(
235235
productSearchStub.then(
236236
stub =>

packages/google-cloud-vision/system-test/image_annotator_smoke_test.js

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

21-
let client = new vision.v1p3beta1.ImageAnnotatorClient({
21+
const client = new vision.v1p3beta1.ImageAnnotatorClient({
2222
// optional auth parameters.
2323
});
2424

25-
let gcsImageUri = 'gs://gapic-toolkit/President_Barack_Obama.jpg';
26-
let source = {
25+
const gcsImageUri = 'gs://gapic-toolkit/President_Barack_Obama.jpg';
26+
const source = {
2727
gcsImageUri: gcsImageUri,
2828
};
29-
let image = {
29+
const image = {
3030
source: source,
3131
};
32-
let type = 'FACE_DETECTION';
33-
let featuresElement = {
32+
const type = 'FACE_DETECTION';
33+
const featuresElement = {
3434
type: type,
3535
};
36-
let features = [featuresElement];
37-
let requestsElement = {
36+
const features = [featuresElement];
37+
const requestsElement = {
3838
image: image,
3939
features: features,
4040
};
41-
let requests = [requestsElement];
41+
const requests = [requestsElement];
4242
client
4343
.batchAnnotateImages({requests: requests})
4444
.then(responses => {
45-
let response = responses[0];
45+
const response = responses[0];
4646
console.log(response);
4747
})
4848
.then(done)

packages/google-cloud-vision/system-test/vision-v1p2beta1.js

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

21-
let client = new vision.v1p2beta1.ImageAnnotatorClient({
21+
const client = new vision.v1p2beta1.ImageAnnotatorClient({
2222
// optional auth parameters.
2323
});
2424

25-
let gcsImageUri = 'gs://gapic-toolkit/President_Barack_Obama.jpg';
26-
let source = {
25+
const gcsImageUri = 'gs://gapic-toolkit/President_Barack_Obama.jpg';
26+
const source = {
2727
gcsImageUri: gcsImageUri,
2828
};
29-
let image = {
29+
const image = {
3030
source: source,
3131
};
32-
let type = 'FACE_DETECTION';
33-
let featuresElement = {
32+
const type = 'FACE_DETECTION';
33+
const featuresElement = {
3434
type: type,
3535
};
36-
let features = [featuresElement];
37-
let requestsElement = {
36+
const features = [featuresElement];
37+
const requestsElement = {
3838
image: image,
3939
features: features,
4040
};
41-
let requests = [requestsElement];
41+
const requests = [requestsElement];
4242
client
4343
.batchAnnotateImages({requests: requests})
4444
.then(responses => {
45-
let response = responses[0];
45+
const response = responses[0];
4646
console.log(response);
4747
})
4848
.then(done)

packages/google-cloud-vision/system-test/vision.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ describe('Vision', function() {
3636

3737
const TESTS_PREFIX = 'gcloud-vision-test';
3838

39-
let storage = new Storage();
40-
let client = new vision.v1.ImageAnnotatorClient();
39+
const storage = new Storage();
40+
const client = new vision.v1.ImageAnnotatorClient();
4141

42-
let bucket = storage.bucket(generateName());
42+
const bucket = storage.bucket(generateName());
4343

4444
before(function(done) {
4545
bucket.create(function(err) {
@@ -80,30 +80,31 @@ describe('Vision', function() {
8080
});
8181

8282
it('should detect from a URL', () => {
83-
let url = 'https://upload.wikimedia.org/wikipedia/commons/5/51/Google.png';
83+
const url =
84+
'https://upload.wikimedia.org/wikipedia/commons/5/51/Google.png';
8485
return client.logoDetection(url).then(responses => {
85-
let response = responses[0];
86+
const response = responses[0];
8687
assert.deepStrictEqual(response.logoAnnotations[0].description, 'Google');
8788
});
8889
});
8990

9091
it('should detect from a filename', () => {
9192
return client.logoDetection(IMAGES.logo).then(responses => {
92-
let response = responses[0];
93+
const response = responses[0];
9394
assert.deepStrictEqual(response.logoAnnotations[0].description, 'Google');
9495
});
9596
});
9697

9798
it('should detect from a Buffer', () => {
98-
let buffer = fs.readFileSync(IMAGES.logo);
99+
const buffer = fs.readFileSync(IMAGES.logo);
99100
return client.logoDetection(buffer).then(responses => {
100-
let response = responses[0];
101+
const response = responses[0];
101102
assert.deepStrictEqual(response.logoAnnotations[0].description, 'Google');
102103
});
103104
});
104105

105106
describe('single image', () => {
106-
let TYPES = [
107+
const TYPES = [
107108
{type: 'FACE_DETECTION'},
108109
{type: 'LABEL_DETECTION'},
109110
{type: 'SAFE_SEARCH_DETECTION'},
@@ -115,7 +116,7 @@ describe('Vision', function() {
115116
image: {source: {filename: IMAGES.rushmore}},
116117
})
117118
.then(responses => {
118-
let response = responses[0];
119+
const response = responses[0];
119120
assert(response.faceAnnotations.length >= 1);
120121
assert(response.labelAnnotations.length >= 1);
121122
assert(response.safeSearchAnnotation !== null);

0 commit comments

Comments
 (0)