diff --git a/.eslintrc.yml b/.eslintrc.yml index 599d506aba..0c755d8b40 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -3,8 +3,8 @@ extends: - 'eslint:recommended' - 'plugin:node/recommended' - prettier -env: - mocha: true +env: + mocha: true plugins: - node - prettier @@ -16,4 +16,4 @@ rules: no-console: off node/no-missing-require: off node/no-unpublished-require: off - + prefer-const: error diff --git a/appengine/headless-chrome/app.js b/appengine/headless-chrome/app.js index 6d8a147cf6..a876fc09a6 100644 --- a/appengine/headless-chrome/app.js +++ b/appengine/headless-chrome/app.js @@ -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(); diff --git a/appengine/memcached/app.js b/appengine/memcached/app.js index e7dcb33d26..f854fd0c3c 100644 --- a/appengine/memcached/app.js +++ b/appengine/memcached/app.js @@ -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] diff --git a/appengine/metadata/standard/server.js b/appengine/metadata/standard/server.js index 35b14ac9fa..10fb46346d 100644 --- a/appengine/metadata/standard/server.js +++ b/appengine/metadata/standard/server.js @@ -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}`) diff --git a/appengine/pubsub/app.js b/appengine/pubsub/app.js index a76f0bf894..2a0efd553a 100644 --- a/appengine/pubsub/app.js +++ b/appengine/pubsub/app.js @@ -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); diff --git a/appengine/typescript/index.ts b/appengine/typescript/index.ts index 0da7e3ee57..5660745a5a 100644 --- a/appengine/typescript/index.ts +++ b/appengine/typescript/index.ts @@ -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}`); }); diff --git a/cloud-sql/postgres/knex/server.js b/cloud-sql/postgres/knex/server.js index 52ec95fafd..d9ccbc55f8 100644 --- a/cloud-sql/postgres/knex/server.js +++ b/cloud-sql/postgres/knex/server.js @@ -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; @@ -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) diff --git a/functions/http/index.js b/functions/http/index.js index 38f3e9baae..79deb162da 100644 --- a/functions/http/index.js +++ b/functions/http/index.js @@ -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; @@ -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) => { diff --git a/functions/log/index.js b/functions/log/index.js index 58f95f3ccc..c9e76d49e1 100644 --- a/functions/log/index.js +++ b/functions/log/index.js @@ -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 = { diff --git a/functions/ocr/app/index.js b/functions/ocr/app/index.js index b67b3ff7d5..d305f67b7a 100644 --- a/functions/ocr/app/index.js +++ b/functions/ocr/app/index.js @@ -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(() => { diff --git a/functions/ocr/app/test/index.test.js b/functions/ocr/app/test/index.test.js index d2ba26d063..55e96b10a8 100644 --- a/functions/ocr/app/test/index.test.js +++ b/functions/ocr/app/test/index.test.js @@ -74,7 +74,7 @@ function getSample() { ); stubInstance = Object.assign(stubInstance, mocks); - let out = {}; + const out = {}; out[property] = sinon.stub().returns(stubInstance); return out; }; diff --git a/functions/sendgrid/test/index.test.js b/functions/sendgrid/test/index.test.js index 573b8831f7..875ee01a56 100644 --- a/functions/sendgrid/test/index.test.js +++ b/functions/sendgrid/test/index.test.js @@ -115,7 +115,7 @@ function getSample() { } function getMocks() { - let req = { + const req = { headers: {}, query: {}, body: {}, @@ -124,7 +124,7 @@ function getMocks() { }, }; sinon.spy(req, 'get'); - let res = { + const res = { headers: {}, send: sinon.stub().returnsThis(), json: sinon.stub().returnsThis(), diff --git a/functions/speech-to-speech/functions/index.js b/functions/speech-to-speech/functions/index.js index 086ea7a0ec..463a31501b 100644 --- a/functions/speech-to-speech/functions/index.js +++ b/functions/speech-to-speech/functions/index.js @@ -39,7 +39,7 @@ const textToSpeechClient = getTextToSpeechClient(); const storageClient = getStorageClient(); exports.speechTranslate = functions.https.onRequest((request, response) => { - let responseBody = {}; + const responseBody = {}; validateRequest(request) .then(() => { @@ -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) diff --git a/functions/speech-to-speech/functions/test/sample.integration.http.test.js b/functions/speech-to-speech/functions/test/sample.integration.http.test.js index 63a5f57267..026dbd32f7 100644 --- a/functions/speech-to-speech/functions/test/sample.integration.http.test.js +++ b/functions/speech-to-speech/functions/test/sample.integration.http.test.js @@ -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) { diff --git a/iot/beta-features/gateway/gateway.js b/iot/beta-features/gateway/gateway.js index 4275dc8211..7c0030832e 100644 --- a/iot/beta-features/gateway/gateway.js +++ b/iot/beta-features/gateway/gateway.js @@ -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 = { @@ -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 = { @@ -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'; @@ -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 ( @@ -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}`); @@ -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}`); @@ -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, @@ -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) { @@ -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}`); @@ -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, @@ -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) { @@ -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}`); }); @@ -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, @@ -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) { @@ -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.`); diff --git a/iot/beta-features/gateway/gateway.test.js b/iot/beta-features/gateway/gateway.test.js index cd46f8e6d3..5169cf002f 100644 --- a/iot/beta-features/gateway/gateway.test.js +++ b/iot/beta-features/gateway/gateway.test.js @@ -59,7 +59,7 @@ after(async () => { it('should create a new gateway', async () => { // create gateway const gatewayId = `nodejs-test-gateway-iot-${uuid.v4()}`; - let gatewayOut = await tools.runAsync( + const gatewayOut = await tools.runAsync( `${cmd} createGateway ${registryName} ${gatewayId} RS256 ${publicKeyParam}` ); // test no error on create gateway assert.strictEqual(new RegExp('Created device').test(gatewayOut), true); @@ -78,7 +78,7 @@ it('should list gateways', async () => { ); // look for output in list gateway - let gateways = await tools.runAsync(`${cmd} listGateways ${registryName}`); + const gateways = await tools.runAsync(`${cmd} listGateways ${registryName}`); assert.strictEqual(new RegExp(`${gatewayId}`).test(gateways), true); await tools.runAsync( @@ -101,7 +101,7 @@ it('should bind existing device to gateway', async () => { ); // bind device to gateway - let bind = await tools.runAsync( + const bind = await tools.runAsync( `${cmd} bindDeviceToGateway ${registryName} ${gatewayId} ${deviceId}` ); @@ -110,7 +110,7 @@ it('should bind existing device to gateway', async () => { assert.strictEqual(new RegExp('Could not bind device').test(bind), false); // test unbind - let unbind = await tools.runAsync( + const unbind = await tools.runAsync( `${cmd} unbindDeviceFromGateway ${registryName} ${gatewayId} ${deviceId}` ); assert.strictEqual(new RegExp('Device no longer bound').test(unbind), true); @@ -133,7 +133,7 @@ it('should bind new device to gateway', async () => { // binding a non-existing device should create it const deviceId = `nodejs-test-device-iot-${uuid.v4()}`; - let bind = await tools.runAsync( + const bind = await tools.runAsync( `${cmd} bindDeviceToGateway ${registryName} ${gatewayId} ${deviceId}` ); @@ -142,7 +142,7 @@ it('should bind new device to gateway', async () => { assert.strictEqual(new RegExp('Could not bind device').test(bind), false); // unbind and delete device and gateway - let unbind = await tools.runAsync( + const unbind = await tools.runAsync( `${cmd} unbindDeviceFromGateway ${registryName} ${gatewayId} ${deviceId}` ); assert.strictEqual(new RegExp('Device no longer bound').test(unbind), true); @@ -169,7 +169,7 @@ it('should list devices bound to gateway', async () => { `${cmd} bindDeviceToGateway ${registryName} ${gatewayId} ${deviceId}` ); - let devices = await tools.runAsync( + const devices = await tools.runAsync( `${cmd} listDevicesForGateway ${registryName} ${gatewayId}` ); @@ -201,7 +201,7 @@ it('should list gateways for bound device', async () => { `${cmd} bindDeviceToGateway ${registryName} ${gatewayId} ${deviceId}` ); - let devices = await tools.runAsync( + const devices = await tools.runAsync( `${cmd} listGatewaysForDevice ${registryName} ${deviceId}` ); @@ -237,7 +237,7 @@ it('should listen for bound device config message', async () => { ); // listen for configuration changes - let out = await tools.runAsync( + const out = await tools.runAsync( `${cmd} listen ${deviceId} ${gatewayId} ${registryName} ${privateKeyParam} --clientDuration=30000` ); @@ -271,7 +271,7 @@ it('should listen for error topic messages', async () => { ); // check error topic contains error of attaching a device that is not bound - let out = await tools.runAsync( + const out = await tools.runAsync( `${cmd} listenForErrors ${gatewayId} ${registryName} ${deviceId} ${privateKeyParam} --clientDuration=30000` ); @@ -306,7 +306,7 @@ it('should send data from bound device', async () => { ); // relay telemetry on behalf of device - let out = await tools.runAsync( + const out = await tools.runAsync( `${cmd} relayData ${deviceId} ${gatewayId} ${registryName} ${privateKeyParam} --numMessages=5` ); diff --git a/iot/http_example/cloudiot_http_example.js b/iot/http_example/cloudiot_http_example.js index 854fda1f9f..a843163365 100644 --- a/iot/http_example/cloudiot_http_example.js +++ b/iot/http_example/cloudiot_http_example.js @@ -101,7 +101,11 @@ var argv = require(`yargs`) // must be in the format below. let iatTime = parseInt(Date.now() / 1000); -let authToken = createJwt(argv.projectId, argv.privateKeyFile, argv.algorithm); +const authToken = createJwt( + argv.projectId, + argv.privateKeyFile, + argv.algorithm +); const devicePath = `projects/${argv.projectId}/locations/${ argv.cloudRegion }/registries/${argv.registryId}/devices/${argv.deviceId}`; @@ -180,7 +184,7 @@ function publishAsync(authToken, messageCount, numMessages) { // If we have published fewer than numMessage messages, publish payload // messageCount + 1. setTimeout(function() { - let secsFromIssue = parseInt(Date.now() / 1000) - iatTime; + const secsFromIssue = parseInt(Date.now() / 1000) - iatTime; if (secsFromIssue > argv.tokenExpMins * 60) { iatTime = parseInt(Date.now() / 1000); console.log(`\tRefreshing token after ${secsFromIssue} seconds.`); diff --git a/iot/manager/manager.js b/iot/manager/manager.js index cb67eded5d..8885add850 100644 --- a/iot/manager/manager.js +++ b/iot/manager/manager.js @@ -476,7 +476,7 @@ function listDevices(client, registryId, projectId, cloudRegion) { console.log('Could not list devices'); console.log(err); } else { - let data = res.data; + const data = res.data; console.log('Current devices in registry:', data['devices']); } }); @@ -501,7 +501,7 @@ function listRegistries(client, projectId, cloudRegion) { console.log('Could not list registries'); console.log(err); } else { - let data = res.data; + const data = res.data; console.log('Current registries in project:\n', data['deviceRegistries']); } }); @@ -573,9 +573,9 @@ function clearRegistry(client, registryId, projectId, cloudRegion) { return; } - let data = res.data; + const data = res.data; console.log('Current devices in registry:', data['devices']); - let devices = data['devices']; + const devices = data['devices']; if (devices) { devices.forEach((device, index) => { @@ -1095,9 +1095,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 = { @@ -1114,9 +1114,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 = { @@ -1159,17 +1159,17 @@ function unbindAllDevices(client, projectId, cloudRegion, registryId) { 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'; @@ -1205,7 +1205,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 ( @@ -1247,7 +1247,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}`); @@ -1285,7 +1285,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}`); diff --git a/iot/manager/system-test/manager.test.js b/iot/manager/system-test/manager.test.js index 8406e3c385..90f4a4f5a3 100644 --- a/iot/manager/system-test/manager.test.js +++ b/iot/manager/system-test/manager.test.js @@ -46,7 +46,7 @@ before(async () => { console.log(`Topic ${topic.name} created.`); // Creates a registry to be used for tests. - let createRegistryRequest = { + const createRegistryRequest = { parent: iotClient.locationPath(projectId, region), deviceRegistry: { id: registryName, @@ -261,7 +261,7 @@ it('should create and get an iam policy', async () => { }); it('should create and delete a registry', async () => { - let createRegistryId = registryName + 'create'; + const createRegistryId = registryName + 'create'; let output = await tools.runAsync(`${cmd} setupIotTopic ${topicName}`, cwd); output = await tools.runAsync( @@ -306,7 +306,7 @@ it('should send command message to device', async () => { it('should create a new gateway', async () => { const gatewayId = `nodejs-test-gateway-iot-${uuid.v4()}`; - let gatewayOut = await tools.runAsync( + const gatewayOut = await tools.runAsync( `${cmd} createGateway ${registryName} ${gatewayId} RSA_X509_PEM ${rsaPublicCert}` ); @@ -325,7 +325,7 @@ it('should list gateways', async () => { ); // look for output in list gateway - let gateways = await tools.runAsync(`${cmd} listGateways ${registryName}`); + const gateways = await tools.runAsync(`${cmd} listGateways ${registryName}`); assert.strictEqual(new RegExp(`${gatewayId}`).test(gateways), true); await iotClient.deleteDevice({ @@ -349,7 +349,7 @@ it('should bind existing device to gateway', async () => { }); // bind device to gateway - let bind = await tools.runAsync( + const bind = await tools.runAsync( `${cmd} bindDeviceToGateway ${registryName} ${gatewayId} ${deviceId}` ); @@ -360,7 +360,7 @@ it('should bind existing device to gateway', async () => { assert.strictEqual(new RegExp('Could not bind device').test(bind), false); // test unbind - let unbind = await tools.runAsync( + const unbind = await tools.runAsync( `${cmd} unbindDeviceFromGateway ${registryName} ${gatewayId} ${deviceId}` ); assert.strictEqual( @@ -395,7 +395,7 @@ it('should list devices bound to gateway', async () => { `${cmd} bindDeviceToGateway ${registryName} ${gatewayId} ${deviceId}` ); - let devices = await tools.runAsync( + const devices = await tools.runAsync( `${cmd} listDevicesForGateway ${registryName} ${gatewayId}` ); @@ -438,7 +438,7 @@ it('should list gateways for bound device', async () => { `${cmd} bindDeviceToGateway ${registryName} ${gatewayId} ${deviceId}` ); - let devices = await tools.runAsync( + const devices = await tools.runAsync( `${cmd} listGatewaysForDevice ${registryName} ${deviceId}` ); diff --git a/iot/mqtt_example/cloudiot_mqtt_example_nodejs.js b/iot/mqtt_example/cloudiot_mqtt_example_nodejs.js index 88bbfc9243..9aae44648a 100644 --- a/iot/mqtt_example/cloudiot_mqtt_example_nodejs.js +++ b/iot/mqtt_example/cloudiot_mqtt_example_nodejs.js @@ -310,7 +310,7 @@ function publishAsync( var schedulePublishDelayMs = argv.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 > argv.tokenExpMins * 60) { iatTime = parseInt(Date.now() / 1000); console.log(`\tRefreshing token after ${secsFromIssue} seconds.`); @@ -408,7 +408,7 @@ function mqttDeviceDemo( // non-empty. The password field is used to transmit a JWT to authorize the // device. The "mqtts" protocol causes the library to connect using SSL, which // is required for Cloud IoT Core. - let connectionArgs = { + const connectionArgs = { host: mqttBridgeHostname, port: mqttBridgePort, clientId: mqttClientId, @@ -419,8 +419,8 @@ function mqttDeviceDemo( }; // 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); // Subscribe to the /devices/{device-id}/config topic to receive config updates. // Config updates are recommended to use QoS 1 (at least once delivery) @@ -578,7 +578,7 @@ function publishAsyncGateway( var schedulePublishDelayMs = 5000; // messageType === 'events' ? 1000 : 2000; setTimeout(function() { - 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.`); @@ -633,7 +633,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, @@ -645,8 +645,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) { @@ -722,7 +722,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, @@ -734,7 +734,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) { @@ -767,7 +767,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}`); @@ -809,7 +809,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, @@ -821,7 +821,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) { @@ -851,7 +851,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}`); }); diff --git a/iot/mqtt_example/system-test/cloudiot_mqtt_example.test.js b/iot/mqtt_example/system-test/cloudiot_mqtt_example.test.js index 5e67a6cb23..beae599bd3 100644 --- a/iot/mqtt_example/system-test/cloudiot_mqtt_example.test.js +++ b/iot/mqtt_example/system-test/cloudiot_mqtt_example.test.js @@ -47,7 +47,7 @@ before(async () => { console.log(`Topic ${topic.name} created.`); // Creates a registry to be used for tests. - let createRegistryRequest = { + const createRegistryRequest = { parent: iotClient.locationPath(projectId, region), deviceRegistry: { id: registryName, @@ -190,7 +190,7 @@ it('should receive command message', async () => { cwd ); - let output = tools.runAsync( + const output = tools.runAsync( `${cmd} mqttDeviceDemo --registryId=${localRegName} --deviceId=${deviceId} --numMessages=30 --privateKeyFile=${rsaPrivateKey} --algorithm=RS256 --mqttBridgePort=443`, cwd ); @@ -228,7 +228,7 @@ it('should listen for bound device config message', async () => { ); // listen for configuration changes - let out = await tools.runAsync( + const out = await tools.runAsync( `${cmd} listenForConfigMessages --deviceId=${deviceId} --gatewayId=${gatewayId} --registryId=${registryName} --privateKeyFile=${rsaPrivateKey} --clientDuration=10000 --algorithm=RS256` ); @@ -264,7 +264,7 @@ it('should listen for error topic messages', async () => { ); // check error topic contains error of attaching a device that is not bound - let out = await tools.runAsync( + const out = await tools.runAsync( `${cmd} listenForErrorMessages --gatewayId=${gatewayId} --registryId=${registryName} --deviceId=${deviceId} --privateKeyFile=${rsaPrivateKey} --clientDuration=30000 --algorithm=RS256` ); @@ -309,7 +309,7 @@ it('should send data from bound device', async () => { ); // relay telemetry on behalf of device - let out = await tools.runAsync( + const out = await tools.runAsync( `${cmd} sendDataFromBoundDevice --deviceId=${deviceId} --gatewayId=${gatewayId} --registryId=${registryName} --privateKeyFile=${rsaPrivateKey} --numMessages=5 --algorithm=RS256` ); diff --git a/package.json b/package.json index 77b6d2f0e2..d73d6a251e 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "private": true, "scripts": { "lint": "eslint '**/*.js'", + "fix": "eslint --fix '**/*.js'", "test": "echo 'Please run tests in each sample directory.' && exit 1" }, "devDependencies": {