Skip to content

Commit 1acf777

Browse files
committed
Use eslint in functions/
Fixes #992
1 parent 455989a commit 1acf777

File tree

92 files changed

+1971
-1491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1971
-1491
lines changed

.eslintignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
**/node_modules/*
2-
functions/**
32
appengine/parse-server/cloud/main.js

functions/background/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ const requestPromiseNative = require('request-promise-native');
4646
* @param {object} event.data The event data.
4747
* @returns {Promise}
4848
*/
49-
exports.helloPromise = (event) => {
49+
exports.helloPromise = event => {
5050
return requestPromiseNative({
51-
uri: event.data.endpoint
51+
uri: event.data.endpoint,
5252
});
5353
};
5454
// [END functions_background_promise]
@@ -61,7 +61,7 @@ exports.helloPromise = (event) => {
6161
* @param {object} event The Cloud Functions event.
6262
* @param {object} event.data The event data.
6363
*/
64-
exports.helloSynchronous = (event) => {
64+
exports.helloSynchronous = event => {
6565
// This function returns synchronously
6666
if (event.data.something === true) {
6767
return 'Something is true!';

functions/background/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
1010
},
1111
"engines": {
12-
"node": ">=4.3.2"
12+
"node": ">=8"
1313
},
1414
"scripts": {
15-
"lint": "semistandard '**/*.js'",
16-
"pretest": "npm run lint",
1715
"test": "ava -T 20s --verbose test/*.test.js"
1816
},
1917
"dependencies": {
@@ -24,7 +22,6 @@
2422
"@google-cloud/nodejs-repo-tools": "^3.0.0",
2523
"ava": "0.25.0",
2624
"proxyquire": "2.1.0",
27-
"semistandard": "^12.0.1",
2825
"sinon": "4.4.2"
2926
},
3027
"cloud-repo-tools": {

functions/background/test/index.test.js

+39-31
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ const sinon = require(`sinon`);
2020
const test = require(`ava`);
2121
const tools = require(`@google-cloud/nodejs-repo-tools`);
2222

23-
function getSample () {
23+
function getSample() {
2424
const requestPromiseNative = sinon.stub().returns(Promise.resolve(`test`));
2525

2626
return {
2727
program: proxyquire(`../`, {
28-
'request-promise-native': requestPromiseNative
28+
'request-promise-native': requestPromiseNative,
2929
}),
3030
mocks: {
31-
requestPromiseNative: requestPromiseNative
32-
}
31+
requestPromiseNative: requestPromiseNative,
32+
},
3333
};
3434
}
3535

3636
test.beforeEach(tools.stubConsole);
3737
test.afterEach.always(tools.restoreConsole);
3838

39-
test.serial(`should echo message`, (t) => {
39+
test.serial(`should echo message`, t => {
4040
const event = {
4141
data: {
42-
myMessage: `hi`
43-
}
42+
myMessage: `hi`,
43+
},
4444
};
4545
const sample = getSample();
4646
const callback = sinon.stub();
@@ -53,45 +53,53 @@ test.serial(`should echo message`, (t) => {
5353
t.deepEqual(callback.firstCall.args, []);
5454
});
5555

56-
test.serial(`should say no message was provided`, (t) => {
56+
test.serial(`should say no message was provided`, t => {
5757
const error = new Error(`No message defined!`);
5858
const callback = sinon.stub();
5959
const sample = getSample();
60-
sample.program.helloWorld({ data: {} }, callback);
60+
sample.program.helloWorld({data: {}}, callback);
6161

6262
t.is(callback.callCount, 1);
6363
t.deepEqual(callback.firstCall.args, [error]);
6464
});
6565

66-
test.serial(`should make a promise request`, (t) => {
66+
test.serial(`should make a promise request`, t => {
6767
const sample = getSample();
6868
const event = {
6969
data: {
70-
endpoint: `foo.com`
71-
}
70+
endpoint: `foo.com`,
71+
},
7272
};
7373

74-
return sample.program.helloPromise(event)
75-
.then((result) => {
76-
t.deepEqual(sample.mocks.requestPromiseNative.firstCall.args, [{ uri: `foo.com` }]);
77-
t.is(result, `test`);
78-
});
74+
return sample.program.helloPromise(event).then(result => {
75+
t.deepEqual(sample.mocks.requestPromiseNative.firstCall.args, [
76+
{uri: `foo.com`},
77+
]);
78+
t.is(result, `test`);
79+
});
7980
});
8081

81-
test.serial(`should return synchronously`, (t) => {
82-
t.is(getSample().program.helloSynchronous({
83-
data: {
84-
something: true
85-
}
86-
}), `Something is true!`);
87-
});
88-
89-
test.serial(`should throw an error`, (t) => {
90-
t.throws(() => {
82+
test.serial(`should return synchronously`, t => {
83+
t.is(
9184
getSample().program.helloSynchronous({
9285
data: {
93-
something: false
94-
}
95-
});
96-
}, Error, `Something was not true!`);
86+
something: true,
87+
},
88+
}),
89+
`Something is true!`
90+
);
91+
});
92+
93+
test.serial(`should throw an error`, t => {
94+
t.throws(
95+
() => {
96+
getSample().program.helloSynchronous({
97+
data: {
98+
something: false,
99+
},
100+
});
101+
},
102+
Error,
103+
`Something was not true!`
104+
);
97105
});

functions/billing/.eslintrc.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
rules:
3+
no-unused-vars: off
4+

functions/billing/index.js

+24-20
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
// [START functions_billing_limit]
1717
// [START functions_billing_stop]
18-
const { google } = require('googleapis');
19-
const { auth } = require('google-auth-library');
18+
const {google} = require('googleapis');
19+
const {auth} = require('google-auth-library');
2020

2121
const PROJECT_ID = process.env.GCP_PROJECT;
2222
const PROJECT_NAME = `projects/${PROJECT_ID}`;
@@ -38,7 +38,7 @@ exports.notifySlack = async (data, context) => {
3838
const res = await slack.chat.postMessage({
3939
token: BOT_ACCESS_TOKEN,
4040
channel: CHANNEL,
41-
text: budgetNotificationText
41+
text: budgetNotificationText,
4242
});
4343
console.log(res);
4444
};
@@ -71,13 +71,13 @@ const _setAuthCredential = async () => {
7171
if (client.hasScopes && !client.hasScopes()) {
7272
client = client.createScoped([
7373
'https://www.googleapis.com/auth/cloud-billing',
74-
'https://www.googleapis.com/auth/cloud-platform'
74+
'https://www.googleapis.com/auth/cloud-platform',
7575
]);
7676
}
7777

7878
// Set credential globally for all requests
7979
google.options({
80-
auth: client
80+
auth: client,
8181
});
8282
};
8383

@@ -86,8 +86,8 @@ const _setAuthCredential = async () => {
8686
* @param {string} projectName Name of project to check if billing is enabled
8787
* @return {bool} Whether project has billing enabled or not
8888
*/
89-
const _isBillingEnabled = async (projectName) => {
90-
const res = await billing.getBillingInfo({ name: projectName });
89+
const _isBillingEnabled = async projectName => {
90+
const res = await billing.getBillingInfo({name: projectName});
9191
return res.data.billingEnabled;
9292
};
9393

@@ -96,10 +96,10 @@ const _isBillingEnabled = async (projectName) => {
9696
* @param {string} projectName Name of project disable billing on
9797
* @return {string} Text containing response from disabling billing
9898
*/
99-
const _disableBillingForProject = async (projectName) => {
99+
const _disableBillingForProject = async projectName => {
100100
const res = await billing.updateBillingInfo({
101101
name: projectName,
102-
resource: { 'billingAccountName': '' } // Disable billing
102+
resource: {billingAccountName: ''}, // Disable billing
103103
});
104104
return `Billing disabled: ${JSON.stringify(res.data)}`;
105105
};
@@ -126,7 +126,7 @@ exports.limitUse = async (data, context) => {
126126
const _listRunningInstances = async (projectId, zone) => {
127127
const res = await compute.instances.list({
128128
project: projectId,
129-
zone: zone
129+
zone: zone,
130130
});
131131

132132
const instances = res.data.items || [];
@@ -142,15 +142,19 @@ const _stopInstances = async (projectId, zone, instanceNames) => {
142142
if (!instanceNames.length) {
143143
return 'No running instances were found.';
144144
}
145-
await Promise.all(instanceNames.map(instanceName => {
146-
return compute.instances.stop({
147-
project: projectId,
148-
zone: zone,
149-
instance: instanceName
150-
}).then((res) => {
151-
console.log('Instance stopped successfully: ' + instanceName);
152-
return res.data;
153-
});
154-
}));
145+
await Promise.all(
146+
instanceNames.map(instanceName => {
147+
return compute.instances
148+
.stop({
149+
project: projectId,
150+
zone: zone,
151+
instance: instanceName,
152+
})
153+
.then(res => {
154+
console.log('Instance stopped successfully: ' + instanceName);
155+
return res.data;
156+
});
157+
})
158+
);
155159
};
156160
// [END functions_billing_limit]

functions/billing/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"version": "0.0.1",
44
"description": "Examples of integrating Cloud Functions with billing",
55
"main": "index.js",
6+
"engines": {
7+
"node": ">=8"
8+
},
69
"scripts": {
7-
"lint": "semistandard '**/*.js'",
8-
"pretest": "npm run lint",
910
"test": "ava test/*"
1011
},
1112
"author": "Ace Nassri <[email protected]>",
@@ -19,7 +20,6 @@
1920
"@google-cloud/nodejs-repo-tools": "^2.2.5",
2021
"ava": "^0.25.0",
2122
"proxyquire": "^2.1.0",
22-
"semistandard": "^13.0.0",
2323
"sinon": "^6.3.4"
2424
}
2525
}

0 commit comments

Comments
 (0)