Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint: Node 8+ WARNINGs --> ERRORs #1489

Merged
merged 40 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
bdbf403
Automated lint fixes
Sep 18, 2019
78705d9
Lint: switch WARNINGs to ERRORs
Sep 18, 2019
6ca6e75
Fix lint: cloudsql
Sep 18, 2019
0986398
Fix lint: datacatalog
Sep 18, 2019
a0ee631
Fix lint: endpoints
Sep 18, 2019
0ffad40
Fix lint: cloud run
Sep 18, 2019
83f3d5f
Fix lint: storage transfer
Sep 20, 2019
666435a
Fix lint: healthcare
Sep 20, 2019
65df9c2
Fix lint: functions/composer-storage-trigger
Sep 20, 2019
9566280
Fix lint: functions/firebase
Sep 20, 2019
4dbadcf
Fix lint: functions/sendgrid
Sep 20, 2019
7c48f36
Fix lint: functions/spanner
Sep 20, 2019
c39574e
Fix lint: functions/env_vars
Sep 20, 2019
8a8fd3e
Fix lint: functions/http
Sep 20, 2019
cfc5a50
Fix lint: functions/imagemagick
Sep 20, 2019
d1759ca
Fix lint: functions/log
Sep 20, 2019
d1bd17c
Fix lint: functions/memorystore/redis
Sep 20, 2019
389bc8b
Fix lint: functions/node8
Sep 20, 2019
f6ba8ae
Fix lint: functions/scheduleinstance
Sep 20, 2019
8dfec0e
Fix lint: functions/slack
Sep 20, 2019
5989c17
Fix lint: functions/sql
Sep 20, 2019
ccf9358
Fix lint: functions/tips
Sep 20, 2019
4e2dc3e
Fix lint: functions/tokenservice/functions
Sep 20, 2019
dbaf523
Fix lint: run/logging-manual
Sep 20, 2019
2196212
Fix lint: datacatalog
Sep 20, 2019
c8eb484
Address comments
Sep 20, 2019
1e8f8b2
Address comments, take 2
Sep 20, 2019
aba93b1
Fix lint: iot
Sep 21, 2019
e4384c0
Auto-lint GCF changes
Sep 21, 2019
92623be
Fix tests
Sep 23, 2019
eedc373
Cloud Run: humor ESLint's race condition warning
Sep 23, 2019
201206c
functions/pubsub tests: increase timeouts to reduce flakiness
Sep 23, 2019
b7474a0
ESLint race condition rule: revert old fix + make rule optional
Sep 23, 2019
1f43014
Merge branch 'master' into linter-errors
Sep 23, 2019
d8c3008
Fix bug in functions/scheduleinstance promise handling
Sep 25, 2019
7c27da4
Merge branch 'linter-errors' of https://github.com/GoogleCloudPlatfor…
Sep 25, 2019
8571c68
Merge branch 'master' into linter-errors
Sep 25, 2019
6b0ef1b
Increase helloworld system test timeout
Sep 25, 2019
d309f23
Merge branch 'linter-errors' of https://github.com/GoogleCloudPlatfor…
Sep 25, 2019
6120423
functions/helloworld: disable flaky system tests
Sep 25, 2019
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
14 changes: 7 additions & 7 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ rules:
prefer-const: error
no-var: error
prefer-arrow-callback: error
no-throw-literal: warn
require-await: warn
promise/prefer-await-to-then: warn
promise/no-nesting: warn
prefer-destructuring: warn
prefer-template: warn
no-throw-literal: error
require-await: error
promise/prefer-await-to-then: error
promise/no-nesting: error
prefer-destructuring: error
prefer-template: error
func-style:
- 1
- error
- expression
- allowArrowFunctions: true
2 changes: 1 addition & 1 deletion cloud-sql/mysql/mysql/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ app.post('/', async (req, res) => {

res
.status(200)
.send('Successfully voted for ' + team + ' at ' + timestamp)
.send(`Successfully voted for ${team} at ${timestamp}`)
.end();
});

Expand Down
24 changes: 12 additions & 12 deletions cloud-sql/postgres/knex/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ const logger = winston.createLogger({

// [START cloud_sql_postgres_connection_pool]
// Initialize Knex, a Node.js SQL query builder library with built-in connection pooling.
const knex = connect();

function connect() {
const connect = () => {
// Configure which instance and what database user to connect with.
// Remember - storing secrets in plaintext is potentially unsafe. Consider using
// something like https://cloud.google.com/kms/ to help keep secrets secret.
Expand Down Expand Up @@ -101,8 +99,10 @@ function connect() {

// [END_EXCLUDE]
return knex;
// [END cloud_sql_postgres_connection_pool]
}
};

const knex = connect();
// [END cloud_sql_postgres_connection_pool]

// [START cloud_sql_example_statement]
/**
Expand All @@ -112,13 +112,13 @@ function connect() {
* @param {object} vote The vote record to insert.
* @returns {Promise}
*/
async function insertVote(knex, vote) {
const insertVote = async (knex, vote) => {
try {
return await knex('votes').insert(vote);
} catch (err) {
throw Error(err);
}
}
};
// [END cloud_sql_example_statement]

/**
Expand All @@ -127,13 +127,13 @@ async function insertVote(knex, vote) {
* @param {object} knex The Knex connection object.
* @returns {Promise}
*/
async function getVotes(knex) {
const getVotes = async knex => {
return await knex
.select('candidate', 'time_cast')
.from('votes')
.orderBy('time_cast', 'desc')
.limit(5);
}
};

/**
* Retrieve the total count of records for a given candidate
Expand All @@ -143,11 +143,11 @@ async function getVotes(knex) {
* @param {object} candidate The candidate for which to get the total vote count
* @returns {Promise}
*/
async function getVoteCount(knex, candidate) {
const getVoteCount = async (knex, candidate) => {
return await knex('votes')
.count('vote_id')
.where('candidate', candidate);
}
};

app.get('/', (req, res) => {
(async function() {
Expand Down Expand Up @@ -212,7 +212,7 @@ app.post('/', async (req, res) => {
try {
await insertVote(knex, vote);
} catch (err) {
logger.error('Error while attempting to submit vote:' + err);
logger.error(`Error while attempting to submit vote:${err}`);
res
.status(500)
.send('Unable to cast vote; see logs for more details.')
Expand Down
17 changes: 9 additions & 8 deletions datacatalog/cloud-client/lookupEntry.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-warning-comments */

/**
* Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -22,32 +24,31 @@
* For more information, see the README.md under /datacatalog and the
* documentation at https://cloud.google.com/data-catalog/docs.
*/
function main(
const main = async (
projectId = process.env.GCLOUD_PROJECT,
datasetId = process.env.GCLOUD_DATASET_ID
) {
) => {
// [START datacatalog_lookup_dataset]
// -------------------------------
// Import required modules.
// -------------------------------
const {DataCatalogClient} = require('@google-cloud/datacatalog').v1beta1;
const datacatalog = new DataCatalogClient();

async function lookup() {
const lookup = async () => {
// TODO(developer): Uncomment the following lines before running the sample.
// const projectId = 'my-project'
// const datasetId = 'my_dataset'
const resourceName = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}`;
const request = {linkedResource: resourceName};
const [result] = await datacatalog.lookupEntry(request);
return result;
}
};

lookup().then(response => {
console.log(response);
});
const response = await lookup();
console.log(response);
// [END datacatalog_lookup_dataset]
}
};

// node lookupEntry.js <projectId> <datasetID>
main(...process.argv.slice(2));
4 changes: 2 additions & 2 deletions endpoints/getting-started-grpc/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

function makeGrpcRequest(JWT_AUTH_TOKEN, API_KEY, HOST, GREETEE) {
const makeGrpcRequest = (JWT_AUTH_TOKEN, API_KEY, HOST, GREETEE) => {
// Uncomment these lines to set their values
// const JWT_AUTH_TOKEN = 'YOUR_JWT_AUTH_TOKEN';
// const API_KEY = 'YOUR_API_KEY';
Expand Down Expand Up @@ -51,7 +51,7 @@ function makeGrpcRequest(JWT_AUTH_TOKEN, API_KEY, HOST, GREETEE) {
console.log(response.message);
}
});
}
};

// The command-line program
const {argv} = require('yargs')
Expand Down
8 changes: 4 additions & 4 deletions endpoints/getting-started-grpc/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ const grpc = require('grpc');
const helloProto = grpc.load(PROTO_PATH).helloworld;

// Implement the SayHello RPC method.
function sayHello(call, callback) {
const sayHello = (call, callback) => {
callback(null, {message: `Hello ${call.request.name}`});
}
};

// Start an RPC server to handle Greeter service requests
function startServer(PORT) {
const startServer = PORT => {
const server = new grpc.Server();
server.addProtoService(helloProto.Greeter.service, {sayHello: sayHello});
server.bind(`0.0.0.0:${PORT}`, grpc.ServerCredentials.createInsecure());
server.start();
}
};

// The command-line program
const {argv} = require('yargs')
Expand Down
4 changes: 2 additions & 2 deletions endpoints/getting-started/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ app.post('/echo', (req, res) => {
.end();
});

function authInfoHandler(req, res) {
const authInfoHandler = (req, res) => {
let authUser = {id: 'anonymous'};
const encodedInfo = req.get('X-Endpoint-API-UserInfo');
if (encodedInfo) {
Expand All @@ -43,7 +43,7 @@ function authInfoHandler(req, res) {
.status(200)
.json(authUser)
.end();
}
};

app.get('/auth/info/googlejwt', authInfoHandler);
app.get('/auth/info/googleidtoken', authInfoHandler);
Expand Down
4 changes: 2 additions & 2 deletions endpoints/getting-started/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const tools = require('@google-cloud/nodejs-repo-tools');

const SAMPLE_PATH = path.join(__dirname, '../app.js');

function getSample() {
const getSample = () => {
const testApp = express();
sinon.stub(testApp, 'listen').callsArg(1);
const expressMock = sinon.stub().returns(testApp);
Expand All @@ -39,7 +39,7 @@ function getSample() {
express: expressMock,
},
};
}
};

beforeEach(tools.stubConsole);
afterEach(tools.restoreConsole);
Expand Down
2 changes: 1 addition & 1 deletion functions/billing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const _stopInstances = async (projectId, zone, instanceNames) => {
instance: instanceName,
})
.then(res => {
console.log('Instance stopped successfully: ' + instanceName);
console.log(`Instance stopped successfully: ${instanceName}`);
return res.data;
});
})
Expand Down
4 changes: 2 additions & 2 deletions functions/composer-storage-trigger/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const proxyquire = require('proxyquire').noCallThru();
const sinon = require('sinon');
const assert = require('assert');

function getSample(FetchStub) {
const getSample = FetchStub => {
return {
program: proxyquire('../', {
'node-fetch': FetchStub,
Expand All @@ -28,7 +28,7 @@ function getSample(FetchStub) {
fetch: FetchStub,
},
};
}
};

it('Handles error in JSON body', async () => {
const event = {
Expand Down
4 changes: 2 additions & 2 deletions functions/env_vars/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const sinon = require('sinon');
const assert = require('assert');
const functions = require('../');

function getMocks() {
const getMocks = () => {
const req = {};
const res = {
send: sinon.stub().returnsThis(),
Expand All @@ -29,7 +29,7 @@ function getMocks() {
req: req,
res: res,
};
}
};

it('should read env vars', () => {
const mocks = getMocks();
Expand Down
2 changes: 1 addition & 1 deletion functions/firebase/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ exports.helloAnalytics = event => {
const {resource} = event;
console.log(`Function triggered by the following event: ${resource}`);

const analyticsEvent = event.data.eventDim[0];
const [analyticsEvent] = event.data.eventDim;
console.log(`Name: ${analyticsEvent.name}`);
console.log(`Timestamp: ${new Date(analyticsEvent.timestampMicros / 1000)}`);

Expand Down
4 changes: 2 additions & 2 deletions functions/firebase/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const sinon = require('sinon');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');

function getSample() {
const getSample = () => {
const firestoreMock = {
doc: sinon.stub().returnsThis(),
set: sinon.stub(),
Expand All @@ -34,7 +34,7 @@ function getSample() {
firestore: firestoreMock,
},
};
}
};

beforeEach(tools.stubConsole);
afterEach(tools.restoreConsole);
Expand Down
22 changes: 11 additions & 11 deletions functions/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exports.helloContent = (req, res) => {
switch (req.get('content-type')) {
// '{"name":"John"}'
case 'application/json':
name = req.body.name;
name = req.body;
ace-n marked this conversation as resolved.
Show resolved Hide resolved
break;

// 'John', stored in a Buffer
Expand All @@ -46,7 +46,7 @@ exports.helloContent = (req, res) => {

// 'name=John' in the body of a POST request (not the URL)
case 'application/x-www-form-urlencoded':
name = req.body.name;
name = req.body;
break;
}

Expand Down Expand Up @@ -167,15 +167,15 @@ exports.uploadFile = (req, res) => {

// Triggered once all uploaded files are processed by Busboy.
// We still need to wait for the disk writes (saves) to complete.
busboy.on('finish', () => {
Promise.all(fileWrites).then(() => {
// TODO(developer): Process saved files here
for (const name in uploads) {
const file = uploads[name];
fs.unlinkSync(file);
}
res.send();
});
busboy.on('finish', async () => {
await Promise.all(fileWrites);

// TODO(developer): Process saved files here
for (const name in uploads) {
ace-n marked this conversation as resolved.
Show resolved Hide resolved
const file = uploads[name];
fs.unlinkSync(file);
}
res.send();
});

busboy.end(req.rawBody);
Expand Down
8 changes: 4 additions & 4 deletions functions/http/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const assert = require('assert');
const uuid = require('uuid');
const tools = require('@google-cloud/nodejs-repo-tools');

function getSample() {
const getSample = () => {
const requestPromise = sinon
.stub()
.returns(new Promise(resolve => resolve('test')));
Expand All @@ -34,9 +34,9 @@ function getSample() {
requestPromise: requestPromise,
},
};
}
};

function getMocks() {
const getMocks = () => {
const req = {
headers: {},
get: function(header) {
Expand Down Expand Up @@ -65,7 +65,7 @@ function getMocks() {
status: sinon.stub().returnsThis(),
},
};
}
};

beforeEach(tools.stubConsole);
afterEach(tools.restoreConsole);
Expand Down
2 changes: 1 addition & 1 deletion functions/imagemagick/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const testFiles = {
offensive: 'zombie.jpg',
};

describe('functions/imagemagick tests', async () => {
describe('functions/imagemagick tests', () => {
let startFF, stopFF;

before(async () => {
Expand Down
Loading