Skip to content

Commit a8383bf

Browse files
JustinBeckwithfhinkel
authored andcommitted
refactor(lint): enable the no-var eslint rule (GoogleCloudPlatform#1226)
1 parent 5d8904f commit a8383bf

12 files changed

Lines changed: 52 additions & 51 deletions

File tree

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ rules:
1717
node/no-missing-require: off
1818
node/no-unpublished-require: off
1919
prefer-const: error
20+
no-var: error

appengine/loopback/server/server.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
'use strict';
22

3-
var loopback = require('loopback');
4-
var boot = require('loopback-boot');
3+
const loopback = require('loopback');
4+
const boot = require('loopback-boot');
55

6-
var app = (module.exports = loopback());
6+
const app = (module.exports = loopback());
77

88
app.start = function() {
99
// start the web server
1010
return app.listen(function() {
1111
app.emit('started');
12-
var baseUrl = app.get('url').replace(/\/$/, '');
12+
const baseUrl = app.get('url').replace(/\/$/, '');
1313
console.log('Web server listening at: %s', baseUrl);
1414
if (app.get('loopback-component-explorer')) {
15-
var explorerPath = app.get('loopback-component-explorer').mountPath;
15+
const explorerPath = app.get('loopback-component-explorer').mountPath;
1616
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
1717
}
1818
});

appengine/mailjet/app.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515

1616
'use strict';
1717

18-
var express = require('express');
19-
var path = require('path');
20-
var bodyParser = require('body-parser');
18+
const express = require('express');
19+
const path = require('path');
20+
const bodyParser = require('body-parser');
2121

2222
// [START gae_flex_mailjet_config]
23-
var Mailjet = require('node-mailjet').connect(
23+
const Mailjet = require('node-mailjet').connect(
2424
process.env.MJ_APIKEY_PUBLIC,
2525
process.env.MJ_APIKEY_PRIVATE
2626
);
2727
// [END gae_flex_mailjet_config]
2828

29-
var app = express();
29+
const app = express();
3030

3131
// Setup view engine
3232
app.set('views', path.join(__dirname, 'views'));
@@ -42,7 +42,7 @@ app.get('/', function(req, res) {
4242

4343
// [START gae_flex_mailjet_send_message]
4444
app.post('/hello', function(req, res, next) {
45-
var options = {
45+
const options = {
4646
Messages: [
4747
{
4848
From: {
@@ -61,7 +61,7 @@ app.post('/hello', function(req, res, next) {
6161
],
6262
};
6363

64-
var request = Mailjet.post('send', {version: 'v3.1'}).request(options);
64+
const request = Mailjet.post('send', {version: 'v3.1'}).request(options);
6565

6666
request
6767
.then(function(response, body) {
@@ -77,7 +77,7 @@ app.post('/hello', function(req, res, next) {
7777
});
7878
// [END gae_flex_mailjet_send_message]
7979

80-
var server = app.listen(process.env.PORT || 8080, function() {
80+
const server = app.listen(process.env.PORT || 8080, function() {
8181
console.log('App listening on port %s', server.address().port);
8282
console.log('Press Ctrl+C to quit.');
8383
});

cloud-sql/mysql/mysql/views/index.pug

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ html(lang="en")
4343
if vote.candidate.trim() === 'TABS'
4444
i(class="material-icons circle green") keyboard_tab
4545
else
46-
i(class="material-icons circle blue") space_bar
47-
span(class="title") A vote for <b>#{vote.candidate}</b>
46+
i(class="material-icons circle blue") space_bar
47+
span(class="title") A vote for <b>#{vote.candidate}</b>
4848
p was cast at #{vote.time_cast}.
4949

5050
script.

containerengine/hello-world/server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
'use strict';
1717

1818
// [START all]
19-
var http = require('http');
20-
var handleRequest = function(req, res) {
19+
const http = require('http');
20+
const handleRequest = function(req, res) {
2121
res.writeHead(200);
2222
res.end('Hello Kubernetes!');
2323
};
24-
var www = http.createServer(handleRequest);
24+
const www = http.createServer(handleRequest);
2525
www.listen(process.env.PORT || 8080);
2626
// [END all]

functions/composer-storage-trigger/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ function authorizeIap(clientId, projectId, userAgent) {
7474
JSON.stringify({alg: 'RS256', typ: 'JWT'})
7575
).toString('base64');
7676

77-
var jwt = '';
78-
var jwtClaimset = '';
77+
let jwt = '';
78+
let jwtClaimset = '';
7979

8080
// Obtain an Oauth2 access token for the appspot service account
8181
return fetch(
@@ -89,17 +89,17 @@ function authorizeIap(clientId, projectId, userAgent) {
8989
if (tokenResponse.error) {
9090
return Promise.reject(tokenResponse.error);
9191
}
92-
var accessToken = tokenResponse.access_token;
93-
var iat = Math.floor(new Date().getTime() / 1000);
94-
var claims = {
92+
const accessToken = tokenResponse.access_token;
93+
const iat = Math.floor(new Date().getTime() / 1000);
94+
const claims = {
9595
iss: SERVICE_ACCOUNT,
9696
aud: 'https://www.googleapis.com/oauth2/v4/token',
9797
iat: iat,
9898
exp: iat + 60,
9999
target_audience: clientId,
100100
};
101101
jwtClaimset = Buffer.from(JSON.stringify(claims)).toString('base64');
102-
var toSign = [JWT_HEADER, jwtClaimset].join('.');
102+
const toSign = [JWT_HEADER, jwtClaimset].join('.');
103103

104104
return fetch(
105105
`https://iam.googleapis.com/v1/projects/${projectId}/serviceAccounts/${SERVICE_ACCOUNT}:signBlob`,
@@ -121,9 +121,9 @@ function authorizeIap(clientId, projectId, userAgent) {
121121
return Promise.reject(body.error);
122122
}
123123
// Request service account signature on header and claimset
124-
var jwtSignature = body.signature;
124+
const jwtSignature = body.signature;
125125
jwt = [JWT_HEADER, jwtClaimset, jwtSignature].join('.');
126-
var form = new FormData();
126+
const form = new FormData();
127127
form.append('grant_type', 'urn:ietf:params:oauth:grant-type:jwt-bearer');
128128
form.append('assertion', jwt);
129129
return fetch('https://www.googleapis.com/oauth2/v4/token', {

functions/imagemagick/test/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const vision = require('@google-cloud/vision').v1p1beta1;
2424
const bucketName = 'my-bucket';
2525
const defaultFileName = 'image.jpg';
2626

27-
var VisionStub = sinon.stub(vision, 'ImageAnnotatorClient');
27+
let VisionStub = sinon.stub(vision, 'ImageAnnotatorClient');
2828
VisionStub.returns({
2929
safeSearchDetection: sinon.stub().returns(
3030
Promise.resolve([

iot/beta-features/gateway/gateway.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ function publishAsync(
835835

836836
// Publish and schedule the next publish.
837837
publishChainInProgress = true;
838-
var publishDelayMs = 0;
838+
let publishDelayMs = 0;
839839
if (shouldBackoff) {
840840
publishDelayMs = 1000 * (backoffTime + Math.random());
841841
backoffTime *= 2;
@@ -860,7 +860,7 @@ function publishAsync(
860860
}
861861
});
862862

863-
var schedulePublishDelayMs = 5000; // messageType === 'events' ? 1000 : 2000;
863+
const schedulePublishDelayMs = 5000; // messageType === 'events' ? 1000 : 2000;
864864
setTimeout(function() {
865865
// [START iot_mqtt_jwt_refresh]
866866
const secsFromIssue = parseInt(Date.now() / 1000) - iatTime;

iot/http_example/cloudiot_http_example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const request = require('retry-request');
2121
// [END iot_http_includes]
2222

2323
console.log('Google Cloud IoT Core HTTP example.');
24-
var argv = require(`yargs`)
24+
const argv = require(`yargs`)
2525
.options({
2626
projectId: {
2727
default: process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT,

iot/mqtt_example/cloudiot_mqtt_example_nodejs.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ const mqtt = require('mqtt');
2222
// [END iot_mqtt_include]
2323

2424
// The initial backoff time after a disconnection occurs, in seconds.
25-
var MINIMUM_BACKOFF_TIME = 1;
25+
const MINIMUM_BACKOFF_TIME = 1;
2626

2727
// The maximum backoff time before giving up, in seconds.
28-
var MAXIMUM_BACKOFF_TIME = 32;
28+
const MAXIMUM_BACKOFF_TIME = 32;
2929

3030
// Whether to wait with exponential backoff before publishing.
31-
var shouldBackoff = false;
31+
let shouldBackoff = false;
3232

3333
// The current backoff time.
34-
var backoffTime = 1;
34+
let backoffTime = 1;
3535

3636
// Whether an asynchronous publish chain is in progress.
37-
var publishChainInProgress = false;
37+
let publishChainInProgress = false;
3838

3939
console.log('Google Cloud IoT Core MQTT example.');
40-
var argv = require(`yargs`)
40+
const argv = require(`yargs`)
4141
.options({
4242
projectId: {
4343
default: process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT,
@@ -285,7 +285,7 @@ function publishAsync(
285285

286286
// Publish and schedule the next publish.
287287
publishChainInProgress = true;
288-
var publishDelayMs = 0;
288+
let publishDelayMs = 0;
289289
if (shouldBackoff) {
290290
publishDelayMs = 1000 * (backoffTime + Math.random());
291291
backoffTime *= 2;
@@ -307,7 +307,7 @@ function publishAsync(
307307
}
308308
});
309309

310-
var schedulePublishDelayMs = argv.messageType === 'events' ? 1000 : 2000;
310+
const schedulePublishDelayMs = argv.messageType === 'events' ? 1000 : 2000;
311311
setTimeout(function() {
312312
// [START iot_mqtt_jwt_refresh]
313313
const secsFromIssue = parseInt(Date.now() / 1000) - iatTime;
@@ -551,7 +551,7 @@ function publishAsyncGateway(
551551

552552
// Publish and schedule the next publish.
553553
publishChainInProgress = true;
554-
var publishDelayMs = 0;
554+
let publishDelayMs = 0;
555555
if (shouldBackoff) {
556556
publishDelayMs = 1000 * (backoffTime + Math.random());
557557
backoffTime *= 2;
@@ -576,7 +576,7 @@ function publishAsyncGateway(
576576
}
577577
});
578578

579-
var schedulePublishDelayMs = 5000; // messageType === 'events' ? 1000 : 2000;
579+
const schedulePublishDelayMs = 5000; // messageType === 'events' ? 1000 : 2000;
580580
setTimeout(function() {
581581
const secsFromIssue = parseInt(Date.now() / 1000) - iatTime;
582582
if (secsFromIssue > tokenExpMins * 60) {

0 commit comments

Comments
 (0)