Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Enable no-var in eslint #198

Merged
merged 2 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ rules:
block-scoped-var: error
eqeqeq: error
no-warning-comments: warn
no-var: error
24 changes: 12 additions & 12 deletions samples/faceDetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
var vision = require('@google-cloud/vision');
let vision = require('@google-cloud/vision');
// [END vision_face_detection_tutorial_imports]
// [START vision_face_detection_tutorial_client]
// Creates a client
var client = new vision.ImageAnnotatorClient();
let client = new vision.ImageAnnotatorClient();

var fs = require('fs');
let fs = require('fs');
// [END vision_face_detection_tutorial_client]

/**
Expand All @@ -40,7 +40,7 @@ function detectFaces(inputFile, callback) {
.faceDetection(request)
.then(results => {
const faces = results[0].faceAnnotations;
var numFaces = faces.length;
let numFaces = faces.length;
console.log('Found ' + numFaces + (numFaces === 1 ? ' face' : ' faces'));
callback(null, faces);
})
Expand All @@ -61,12 +61,12 @@ function highlightFaces(inputFile, faces, outputFile, Canvas, callback) {
return callback(err);
}

var Image = Canvas.Image;
let Image = Canvas.Image;
// Open the original image into a canvas
var img = new Image();
let img = new Image();
img.src = image;
var canvas = new Canvas(img.width, img.height);
var context = canvas.getContext('2d');
let canvas = new Canvas(img.width, img.height);
let context = canvas.getContext('2d');
context.drawImage(img, 0, 0, img.width, img.height);

// Now draw boxes around all the faces
Expand All @@ -90,8 +90,8 @@ function highlightFaces(inputFile, faces, outputFile, Canvas, callback) {

// Write the result to a file
console.log('Writing to file ' + outputFile);
var writeStream = fs.createWriteStream(outputFile);
var pngStream = canvas.pngStream();
let writeStream = fs.createWriteStream(outputFile);
let pngStream = canvas.pngStream();

pngStream.on('data', chunk => {
writeStream.write(chunk);
Expand Down Expand Up @@ -131,7 +131,7 @@ if (module === require.main) {
// eslint-disable-next-line no-process-exit
process.exit(1);
}
var inputFile = process.argv[2];
var outputFile = process.argv[3];
let inputFile = process.argv[2];
let outputFile = process.argv[3];
exports.main(inputFile, outputFile, require('canvas'), console.log);
}
58 changes: 29 additions & 29 deletions samples/textDetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@

'use strict';

var async = require('async');
var fs = require('fs');
var path = require('path');
let async = require('async');
let fs = require('fs');
let path = require('path');

// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
var vision = require('@google-cloud/vision');
var natural = require('natural');
var redis = require('redis');
let vision = require('@google-cloud/vision');
let natural = require('natural');
let redis = require('redis');

// Instantiate a vision client
var client = new vision.ImageAnnotatorClient();
let client = new vision.ImageAnnotatorClient();

function Index() {
// Connect to a redis server.
var TOKEN_DB = 0;
var DOCS_DB = 1;
var PORT = process.env.REDIS_PORT || '6379';
var HOST = process.env.REDIS_HOST || '127.0.0.1';
let TOKEN_DB = 0;
let DOCS_DB = 1;
let PORT = process.env.REDIS_PORT || '6379';
let HOST = process.env.REDIS_HOST || '127.0.0.1';

this.tokenClient = redis
.createClient(PORT, HOST, {
Expand All @@ -59,12 +59,12 @@ Index.prototype.quit = function() {
};

Index.prototype.add = function(filename, document, callback) {
var self = this;
var PUNCTUATION = ['.', ',', ':', ''];
var tokenizer = new natural.WordTokenizer();
var tokens = tokenizer.tokenize(document);
let self = this;
let PUNCTUATION = ['.', ',', ':', ''];
let tokenizer = new natural.WordTokenizer();
let tokens = tokenizer.tokenize(document);

var tasks = tokens
let tasks = tokens
.filter(function(token) {
return PUNCTUATION.indexOf(token) === -1;
})
Expand All @@ -82,8 +82,8 @@ Index.prototype.add = function(filename, document, callback) {
};

Index.prototype.lookup = function(words, callback) {
var self = this;
var tasks = words.map(function(word) {
let self = this;
let tasks = words.map(function(word) {
word = word.toLowerCase();
return function(cb) {
self.tokenClient.smembers(word, cb);
Expand Down Expand Up @@ -114,7 +114,7 @@ Index.prototype.setContainsNoText = function(filename, callback) {
};

function lookup(words, callback) {
var index = new Index();
let index = new Index();
index.lookup(words, function(err, hits) {
index.quit();
if (err) {
Expand All @@ -128,7 +128,7 @@ function lookup(words, callback) {
}

function extractDescription(texts) {
var document = '';
let document = '';
texts.forEach(function(text) {
document += text.description || '';
});
Expand Down Expand Up @@ -158,10 +158,10 @@ function getTextFromFiles(index, inputFiles, callback) {
.batchAnnotateImages({requests: requests})
.then(results => {
let detections = results[0].responses;
var textResponse = {};
var tasks = [];
let textResponse = {};
let tasks = [];
inputFiles.forEach(function(filename, i) {
var response = detections[i];
let response = detections[i];
if (response.error) {
console.log('API Error for ' + filename, response.error);
return;
Expand All @@ -186,7 +186,7 @@ function getTextFromFiles(index, inputFiles, callback) {

// Run the example
function main(inputDir, callback) {
var index = new Index();
let index = new Index();

async.waterfall(
[
Expand All @@ -198,7 +198,7 @@ function main(inputDir, callback) {
function(files, cb) {
async.parallel(
files.map(function(file) {
var filename = path.join(inputDir, file);
let filename = path.join(inputDir, file);
return function(cb) {
fs.stat(filename, function(err, stats) {
if (err) {
Expand All @@ -216,7 +216,7 @@ function main(inputDir, callback) {
},
// Figure out which files have already been processed
function(allImageFiles, cb) {
var tasks = allImageFiles
let tasks = allImageFiles
.filter(function(filename) {
return filename;
})
Expand Down Expand Up @@ -256,16 +256,16 @@ function main(inputDir, callback) {
}

if (module === require.main) {
var generalError =
let generalError =
'Usage: node textDetection <command> <arg> ...\n\n' +
'\tCommands: analyze, lookup';
if (process.argv.length < 3) {
console.log(generalError);
// eslint-disable-next-line no-process-exit
process.exit(1);
}
var args = process.argv.slice(2);
var command = args.shift();
let args = process.argv.slice(2);
let command = args.shift();
if (command === 'analyze') {
if (!args.length) {
console.log('Usage: node textDetection analyze <dir>');
Expand Down
6 changes: 3 additions & 3 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ let _coerceRequest = (request, callback) => {
* @returns {function} The function that, when called, will call annotateImage
* asking for the single feature annotation.
*/
var _createSingleFeatureMethod = featureValue => {
let _createSingleFeatureMethod = featureValue => {
return function(annotateImageRequest, callOptions, callback) {
// Sanity check: If we got a string or buffer, we need this to be
// in object form now, so we can tack on the features list.
Expand Down Expand Up @@ -152,7 +152,7 @@ var _createSingleFeatureMethod = featureValue => {
* onto the pure GAPIC.
*/
module.exports = apiVersion => {
var methods = {};
let methods = {};

/**
* Annotate a single image with the requested features.
Expand Down Expand Up @@ -236,7 +236,7 @@ module.exports = apiVersion => {

// We are guaranteed to only have one response element, since we
// only sent one image.
var response = r.responses[0];
let response = r.responses[0];

// Fire the callback if applicable.
return callback(undefined, response);
Expand Down
20 changes: 10 additions & 10 deletions system-test/image_annotator_smoke_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ describe('ImageAnnotatorSmokeTest', () => {
it('successfully makes a call to the service', done => {
const vision = require('../src');

var client = new vision.v1p3beta1.ImageAnnotatorClient({
let client = new vision.v1p3beta1.ImageAnnotatorClient({
// optional auth parameters.
});

var gcsImageUri = 'gs://gapic-toolkit/President_Barack_Obama.jpg';
var source = {
let gcsImageUri = 'gs://gapic-toolkit/President_Barack_Obama.jpg';
let source = {
gcsImageUri: gcsImageUri,
};
var image = {
let image = {
source: source,
};
var type = 'FACE_DETECTION';
var featuresElement = {
let type = 'FACE_DETECTION';
let featuresElement = {
type: type,
};
var features = [featuresElement];
var requestsElement = {
let features = [featuresElement];
let requestsElement = {
image: image,
features: features,
};
var requests = [requestsElement];
let requests = [requestsElement];
client
.batchAnnotateImages({requests: requests})
.then(responses => {
var response = responses[0];
let response = responses[0];
console.log(response);
})
.then(done)
Expand Down
20 changes: 10 additions & 10 deletions system-test/vision-v1p2beta1.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ describe('ImageAnnotatorSmokeTest', () => {
it('successfully makes a call to the service', done => {
const vision = require('../src');

var client = new vision.v1p2beta1.ImageAnnotatorClient({
let client = new vision.v1p2beta1.ImageAnnotatorClient({
// optional auth parameters.
});

var gcsImageUri = 'gs://gapic-toolkit/President_Barack_Obama.jpg';
var source = {
let gcsImageUri = 'gs://gapic-toolkit/President_Barack_Obama.jpg';
let source = {
gcsImageUri: gcsImageUri,
};
var image = {
let image = {
source: source,
};
var type = 'FACE_DETECTION';
var featuresElement = {
let type = 'FACE_DETECTION';
let featuresElement = {
type: type,
};
var features = [featuresElement];
var requestsElement = {
let features = [featuresElement];
let requestsElement = {
image: image,
features: features,
};
var requests = [requestsElement];
let requests = [requestsElement];
client
.batchAnnotateImages({requests: requests})
.then(responses => {
var response = responses[0];
let response = responses[0];
console.log(response);
})
.then(done)
Expand Down
14 changes: 7 additions & 7 deletions system-test/vision.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,30 @@ describe('Vision', function() {
});

it('should detect from a URL', () => {
var url = 'https://upload.wikimedia.org/wikipedia/commons/5/51/Google.png';
let url = 'https://upload.wikimedia.org/wikipedia/commons/5/51/Google.png';
return client.logoDetection(url).then(responses => {
var response = responses[0];
let response = responses[0];
assert.deepStrictEqual(response.logoAnnotations[0].description, 'Google');
});
});

it('should detect from a filename', () => {
return client.logoDetection(IMAGES.logo).then(responses => {
var response = responses[0];
let response = responses[0];
assert.deepStrictEqual(response.logoAnnotations[0].description, 'Google');
});
});

it('should detect from a Buffer', () => {
var buffer = fs.readFileSync(IMAGES.logo);
let buffer = fs.readFileSync(IMAGES.logo);
return client.logoDetection(buffer).then(responses => {
var response = responses[0];
let response = responses[0];
assert.deepStrictEqual(response.logoAnnotations[0].description, 'Google');
});
});

describe('single image', () => {
var TYPES = [
let TYPES = [
{type: 'FACE_DETECTION'},
{type: 'LABEL_DETECTION'},
{type: 'SAFE_SEARCH_DETECTION'},
Expand All @@ -115,7 +115,7 @@ describe('Vision', function() {
image: {source: {filename: IMAGES.rushmore}},
})
.then(responses => {
var response = responses[0];
let response = responses[0];
assert(response.faceAnnotations.length >= 1);
assert(response.labelAnnotations.length >= 1);
assert(response.safeSearchAnnotation !== null);
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe('Vision helper methods', () => {

// Ensure that the annotateImage method arrifies the request and
// passes it through to the batch annotation method.
var request = {
let request = {
image: {content: Buffer.from('bogus==')},
features: {type: ['LOGO_DETECTION']},
};
Expand Down