Skip to content

Commit

Permalink
refactor(lint): prefer const over var (#1224)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and fhinkel committed Mar 26, 2019
1 parent a188cd9 commit 2482f90
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 102 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ extends:
- 'eslint:recommended'
- 'plugin:node/recommended'
- prettier
env:
mocha: true
env:
mocha: true
plugins:
- node
- prettier
Expand All @@ -16,4 +16,4 @@ rules:
no-console: off
node/no-missing-require: off
node/no-unpublished-require: off

prefer-const: error
2 changes: 1 addition & 1 deletion appengine/headless-chrome/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ app.use(async (req, res) => {
// [END browser]
}

let page = await browser.newPage();
const page = await browser.newPage();
await page.goto(url);
const imageBuffer = await page.screenshot();

Expand Down
2 changes: 1 addition & 1 deletion appengine/memcached/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const app = express();

// [START gae_flex_redislabs_memcache]
// Environment variables are defined in app.yaml.
let MEMCACHE_URL = process.env.MEMCACHE_URL;
const MEMCACHE_URL = process.env.MEMCACHE_URL;

const mc = memjs.Client.create(MEMCACHE_URL);
// [END gae_flex_redislabs_memcache]
Expand Down
4 changes: 2 additions & 2 deletions appengine/metadata/standard/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ function getProjectId() {

app.get('/', async (req, res, next) => {
try {
let response = await getProjectId();
let projectId = response.body;
const response = await getProjectId();
const projectId = response.body;
res
.status(200)
.send(`Project ID: ${projectId}`)
Expand Down
4 changes: 2 additions & 2 deletions appengine/pubsub/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ app.post('/', formBodyParser, async (req, res, next) => {
return;
}

let data = Buffer.from(req.body.payload);
const data = Buffer.from(req.body.payload);
try {
let messageId = await publisher.publish(data);
const messageId = await publisher.publish(data);
res.status(200).send(`Message ${messageId} sent.`);
} catch (error) {
next(error);
Expand Down
2 changes: 1 addition & 1 deletion appengine/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ app.get("/", (req, res) => {
res.send("🎉 Hello TypeScript! 🎉");
});

const server: object = app.listen(PORT, () => {
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
});
12 changes: 6 additions & 6 deletions cloud-sql/postgres/knex/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ async function getVoteCount(knex, candidate) {
app.get('/', (req, res) => {
(async function() {
// Query the total count of "TABS" from the database.
let tabsResult = await getVoteCount(knex, 'TABS');
let tabsTotalVotes = parseInt(tabsResult[0].count);
const tabsResult = await getVoteCount(knex, 'TABS');
const tabsTotalVotes = parseInt(tabsResult[0].count);
// Query the total count of "SPACES" from the database.
let spacesResult = await getVoteCount(knex, 'SPACES');
let spacesTotalVotes = parseInt(spacesResult[0].count);
const spacesResult = await getVoteCount(knex, 'SPACES');
const spacesTotalVotes = parseInt(spacesResult[0].count);
// Query the last 5 votes from the database.
let votes = await getVotes(knex);
const votes = await getVotes(knex);
// Calculate and set leader values.
let leadTeam = '';
let voteDiff = 0;
Expand Down Expand Up @@ -219,7 +219,7 @@ app.post('/', (req, res) => {
.send(msg)
.end();
});
let msg = 'Successfully voted for ' + team + ' at ' + timestamp;
const msg = 'Successfully voted for ' + team + ' at ' + timestamp;
res
.status(200)
.send(msg)
Expand Down
6 changes: 3 additions & 3 deletions functions/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ exports.helloHttp = (req, res) => {
exports.parseXML = (req, res) => {
// Convert the request to a Buffer and a string
// Use whichever one is accepted by your XML parser
let data = req.rawBody;
let xmlData = data.toString();
const data = req.rawBody;
const xmlData = data.toString();

const parseString = require('xml2js').parseString;

Expand Down Expand Up @@ -151,7 +151,7 @@ exports.uploadFile = (req, res) => {
fields[fieldname] = val;
});

let fileWrites = [];
const fileWrites = [];

// This code will process each file uploaded.
busboy.on('file', (fieldname, file, filename) => {
Expand Down
2 changes: 1 addition & 1 deletion functions/log/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function getMetrics(callback) {
const monitoring = Monitoring.v3().metricServiceApi();

// Create two datestrings, a start and end range
let oneWeekAgo = new Date();
const oneWeekAgo = new Date();
oneWeekAgo.setHours(oneWeekAgo.getHours() - 7 * 24);

const options = {
Expand Down
2 changes: 1 addition & 1 deletion functions/ocr/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function renameImageForSave(filename, lang) {
* @param {object} event (Node 8+) A Google Cloud Storage File object.
*/
exports.processImage = event => {
let file = event.data || event;
const file = event.data || event;

return Promise.resolve()
.then(() => {
Expand Down
2 changes: 1 addition & 1 deletion functions/ocr/app/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function getSample() {
);
stubInstance = Object.assign(stubInstance, mocks);

let out = {};
const out = {};
out[property] = sinon.stub().returns(stubInstance);
return out;
};
Expand Down
4 changes: 2 additions & 2 deletions functions/sendgrid/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function getSample() {
}

function getMocks() {
let req = {
const req = {
headers: {},
query: {},
body: {},
Expand All @@ -124,7 +124,7 @@ function getMocks() {
},
};
sinon.spy(req, 'get');
let res = {
const res = {
headers: {},
send: sinon.stub().returnsThis(),
json: sinon.stub().returnsThis(),
Expand Down
6 changes: 3 additions & 3 deletions functions/speech-to-speech/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const textToSpeechClient = getTextToSpeechClient();
const storageClient = getStorageClient();

exports.speechTranslate = functions.https.onRequest((request, response) => {
let responseBody = {};
const responseBody = {};

validateRequest(request)
.then(() => {
Expand Down Expand Up @@ -70,9 +70,9 @@ exports.speechTranslate = functions.https.onRequest((request, response) => {
responseBody.transcription = transcription;
responseBody.gcsBucket = outputBucket;

let translations = [];
const translations = [];
supportedLanguageCodes.forEach(languageCode => {
let translation = {languageCode: languageCode};
const translation = {languageCode: languageCode};
const filenameUUID = uuid();
const filename = filenameUUID + '.' + outputAudioEncoding.toLowerCase();
callTextTranslation(languageCode, transcription)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('Tests that require a GCS bucket', function() {
fs.readFileSync('responseBody.test.json')
);

let deletedFiles = [];
const deletedFiles = [];
// Delete the files created in the successful test.
for (let i = 0; i < responseBody.translations.length; i++) {
if (responseBody.translations[i].gcsPath) {
Expand Down
40 changes: 20 additions & 20 deletions iot/beta-features/gateway/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ function unbindDeviceFromAllGateways(
return;
}

let device = res.data;
const device = res.data;
if (device) {
let isGateway = device.gatewayConfig.gatewayType === 'GATEWAY';
const isGateway = device.gatewayConfig.gatewayType === 'GATEWAY';

if (!isGateway) {
const listGatewaysForDeviceRequest = {
Expand All @@ -345,9 +345,9 @@ function unbindDeviceFromAllGateways(
return;
}

let data = res.data;
const data = res.data;
if (data.devices && data.devices.length > 0) {
let gateways = data.devices;
const gateways = data.devices;

gateways.forEach(gateway => {
const unbindRequest = {
Expand Down Expand Up @@ -389,17 +389,17 @@ function unbindAllDevices(client, projectId, cloudRegion, registryId) {
console.error('Could not list devices', err);
return;
}
let data = res.data;
const data = res.data;
if (!data) {
return;
}

let devices = data.devices;
const devices = data.devices;

if (devices && devices.length > 0) {
devices.forEach(device => {
if (device) {
let isGateway =
const isGateway =
device.gatewayConfig &&
device.gatewayConfig.gatewayType === 'GATEWAY';

Expand Down Expand Up @@ -435,7 +435,7 @@ function listGateways(client, projectId, cloudRegion, registryId) {
console.log('Could not list devices');
console.log(err);
} else {
let data = res.data;
const data = res.data;
console.log('Current gateways in registry:');
data.devices.forEach(function(device) {
if (
Expand Down Expand Up @@ -477,7 +477,7 @@ function listDevicesForGateway(
console.log(err);
} else {
console.log('Current devices bound to gateway: ', gatewayId);
let data = res.data;
const data = res.data;
if (data.devices && data.devices.length > 0) {
data.devices.forEach(device => {
console.log(`\tDevice: ${device.numId} : ${device.id}`);
Expand Down Expand Up @@ -515,7 +515,7 @@ function listGatewaysForDevice(
console.log(err);
} else {
console.log('Current gateways for device:', deviceId);
let data = res.data;
const data = res.data;
if (data.devices && data.devices.length > 0) {
data.devices.forEach(gateway => {
console.log(`\tDevice: ${gateway.numId} : ${gateway.id}`);
Expand Down Expand Up @@ -582,7 +582,7 @@ function listenForConfigMessages(

const mqttClientId = `projects/${projectId}/locations/${region}/registries/${registryId}/devices/${gatewayId}`;
console.log(mqttClientId);
let connectionArgs = {
const connectionArgs = {
host: mqttBridgeHostname,
port: mqttBridgePort,
clientId: mqttClientId,
Expand All @@ -594,7 +594,7 @@ function listenForConfigMessages(
};

// Create a client, and connect to the Google MQTT bridge.
let client = mqtt.connect(connectionArgs);
const client = mqtt.connect(connectionArgs);

client.on('connect', success => {
if (!success) {
Expand Down Expand Up @@ -627,7 +627,7 @@ function listenForConfigMessages(
});

client.on('message', (topic, message) => {
let decodedMessage = Buffer.from(message, 'base64').toString('ascii');
const decodedMessage = Buffer.from(message, 'base64').toString('ascii');

if (topic === `/devices/${gatewayId}/errors`) {
console.log(`message received on error topic: ${decodedMessage}`);
Expand Down Expand Up @@ -661,7 +661,7 @@ function listenForErrorMessages(

const mqttClientId = `projects/${projectId}/locations/${region}/registries/${registryId}/devices/${gatewayId}`;
console.log(mqttClientId);
let connectionArgs = {
const connectionArgs = {
host: mqttBridgeHostname,
port: mqttBridgePort,
clientId: mqttClientId,
Expand All @@ -673,7 +673,7 @@ function listenForErrorMessages(
};

// Create a client, and connect to the Google MQTT bridge.
let client = mqtt.connect(connectionArgs);
const client = mqtt.connect(connectionArgs);

client.on('connect', success => {
if (!success) {
Expand Down Expand Up @@ -703,7 +703,7 @@ function listenForErrorMessages(
});

client.on('message', (topic, message) => {
let decodedMessage = Buffer.from(message, 'base64').toString('ascii');
const decodedMessage = Buffer.from(message, 'base64').toString('ascii');

console.log(`message received on error topic ${topic}: ${decodedMessage}`);
});
Expand Down Expand Up @@ -739,7 +739,7 @@ function sendDataFromBoundDevice(

const mqttClientId = `projects/${projectId}/locations/${region}/registries/${registryId}/devices/${gatewayId}`;
console.log(`MQTT client id: ${mqttClientId}`);
let connectionArgs = {
const connectionArgs = {
host: mqttBridgeHostname,
port: mqttBridgePort,
clientId: mqttClientId,
Expand All @@ -751,8 +751,8 @@ function sendDataFromBoundDevice(
};

// Create a client, and connect to the Google MQTT bridge.
let iatTime = parseInt(Date.now() / 1000);
let client = mqtt.connect(connectionArgs);
const iatTime = parseInt(Date.now() / 1000);
const client = mqtt.connect(connectionArgs);

client.on('connect', success => {
if (!success) {
Expand Down Expand Up @@ -863,7 +863,7 @@ function publishAsync(
var schedulePublishDelayMs = 5000; // messageType === 'events' ? 1000 : 2000;
setTimeout(function() {
// [START iot_mqtt_jwt_refresh]
let secsFromIssue = parseInt(Date.now() / 1000) - iatTime;
const secsFromIssue = parseInt(Date.now() / 1000) - iatTime;
if (secsFromIssue > tokenExpMins * 60) {
iatTime = parseInt(Date.now() / 1000);
console.log(`\tRefreshing token after ${secsFromIssue} seconds.`);
Expand Down
Loading

0 comments on commit 2482f90

Please sign in to comment.