Skip to content

Commit 8d66bd4

Browse files
JustinBeckwithfhinkel
authored andcommitted
refactor(lint): prefer arrow callbacks (GoogleCloudPlatform#1228)
1 parent cb2a96e commit 8d66bd4

19 files changed

Lines changed: 85 additions & 86 deletions

File tree

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ rules:
1818
node/no-unpublished-require: off
1919
prefer-const: error
2020
no-var: error
21+
prefer-arrow-callback: error

appengine/loopback/common/models/message.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module.exports = function(Message) {
44
Message.greet = function(msg, cb) {
5-
process.nextTick(function() {
5+
process.nextTick(() => {
66
msg = msg || 'hello';
77
cb(null, 'Sender says ' + msg + ' to receiver');
88
});

appengine/loopback/server/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const app = (module.exports = loopback());
77

88
app.start = function() {
99
// start the web server
10-
return app.listen(function() {
10+
return app.listen(() => {
1111
app.emit('started');
1212
const baseUrl = app.get('url').replace(/\/$/, '');
1313
console.log('Web server listening at: %s', baseUrl);
@@ -20,7 +20,7 @@ app.start = function() {
2020

2121
// Bootstrap the application, configure models, datasources and middleware.
2222
// Sub-apps like REST API are mounted via boot scripts.
23-
boot(app, __dirname, function(err) {
23+
boot(app, __dirname, err => {
2424
if (err) throw err;
2525

2626
// start the server if `$ node server.js`

appengine/mailjet/app.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ app.set('view engine', 'jade');
3636
app.use(bodyParser.json());
3737
app.use(bodyParser.urlencoded({extended: false}));
3838

39-
app.get('/', function(req, res) {
39+
app.get('/', (req, res) => {
4040
res.render('index');
4141
});
4242

4343
// [START gae_flex_mailjet_send_message]
44-
app.post('/hello', function(req, res, next) {
44+
app.post('/hello', (req, res, next) => {
4545
const options = {
4646
Messages: [
4747
{
@@ -64,20 +64,20 @@ app.post('/hello', function(req, res, next) {
6464
const request = Mailjet.post('send', {version: 'v3.1'}).request(options);
6565

6666
request
67-
.then(function(response, body) {
67+
.then((response, body) => {
6868
console.log(response.statusCode, body);
6969
// Render the index route on success
7070
return res.render('index', {
7171
sent: true,
7272
});
7373
})
74-
.catch(function(err) {
74+
.catch(err => {
7575
return next(err);
7676
});
7777
});
7878
// [END gae_flex_mailjet_send_message]
7979

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

cloud-sql/mysql/mysql/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const pool = mysql.createPool({
8787
// [END cloud_sql_mysql_mysql_create]
8888

8989
// When the server starts, check for tables in the database.
90-
app.on('listening', async function() {
90+
app.on('listening', async () => {
9191
// Wait for tables to be created (if they don't already exist).
9292
await pool.query(
9393
`CREATE TABLE IF NOT EXISTS votes

functions/composer-storage-trigger/index.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,15 @@ exports.triggerDag = function triggerDag(event) {
5050
const BODY = {conf: JSON.stringify(event.data)};
5151

5252
// Make the request
53-
return authorizeIap(CLIENT_ID, PROJECT_ID, USER_AGENT).then(
54-
function iapAuthorizationCallback(iap) {
55-
return makeIapPostRequest(
56-
WEBSERVER_URL,
57-
BODY,
58-
iap.idToken,
59-
USER_AGENT,
60-
iap.jwt
61-
);
62-
}
63-
);
53+
return authorizeIap(CLIENT_ID, PROJECT_ID, USER_AGENT).then(iap => {
54+
return makeIapPostRequest(
55+
WEBSERVER_URL,
56+
BODY,
57+
iap.idToken,
58+
USER_AGENT,
59+
iap.jwt
60+
);
61+
});
6462
};
6563

6664
/**
@@ -85,7 +83,7 @@ function authorizeIap(clientId, projectId, userAgent) {
8583
}
8684
)
8785
.then(res => res.json())
88-
.then(function obtainAccessTokenCallback(tokenResponse) {
86+
.then(tokenResponse => {
8987
if (tokenResponse.error) {
9088
return Promise.reject(tokenResponse.error);
9189
}
@@ -116,7 +114,7 @@ function authorizeIap(clientId, projectId, userAgent) {
116114
);
117115
})
118116
.then(res => res.json())
119-
.then(function signJsonClaimCallback(body) {
117+
.then(body => {
120118
if (body.error) {
121119
return Promise.reject(body.error);
122120
}
@@ -132,7 +130,7 @@ function authorizeIap(clientId, projectId, userAgent) {
132130
});
133131
})
134132
.then(res => res.json())
135-
.then(function returnJwt(body) {
133+
.then(body => {
136134
if (body.error) {
137135
return Promise.reject(body.error);
138136
}
@@ -157,7 +155,7 @@ function makeIapPostRequest(url, body, idToken, userAgent) {
157155
Authorization: `Bearer ${idToken}`,
158156
},
159157
body: JSON.stringify(body),
160-
}).then(function checkIapRequestStatus(res) {
158+
}).then(res => {
161159
if (!res.ok) {
162160
return res.text().then(body => Promise.reject(body));
163161
}

functions/dialogflow/functions/test/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const index = require('../index.js');
33
const supertest = require('supertest');
44
const request = supertest(process.env.BASE_URL);
55

6-
describe('Firebase OAuth Token', function() {
7-
it('should give 400 if no argument is provided.', function(done) {
6+
describe('Firebase OAuth Token', () => {
7+
it('should give 400 if no argument is provided.', done => {
88
request
99
.get('/getOAuthToken')
1010
.send()

functions/http/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ exports.getSignedUrl = (req, res) => {
221221
contentType: req.body.contentType,
222222
};
223223

224-
file.getSignedUrl(config, function(err, url) {
224+
file.getSignedUrl(config, (err, url) => {
225225
if (err) {
226226
console.error(err);
227227
res.status(500).end();

functions/speech-to-speech/functions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function uploadToCloudStorage(path, contents) {
173173

174174
// [START validate_request]
175175
function validateRequest(request) {
176-
return new Promise(function(resolve, reject) {
176+
return new Promise((resolve, reject) => {
177177
if (!request.body.encoding) {
178178
reject(new Error('Invalid encoding.'));
179179
}

functions/speech-to-speech/functions/test/index.test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
const supertest = require('supertest');
1919
const request = supertest(process.env.BASE_URL);
2020

21-
describe('Validate encoding field', function() {
22-
it('should fail if encoding field is missing.', function(done) {
21+
describe('Validate encoding field', () => {
22+
it('should fail if encoding field is missing.', done => {
2323
request
2424
.post('/speechTranslate')
2525
.send({
@@ -30,7 +30,7 @@ describe('Validate encoding field', function() {
3030
})
3131
.expect(400, 'Invalid encoding.', done);
3232
});
33-
it('should fail if encoding field is empty.', function(done) {
33+
it('should fail if encoding field is empty.', done => {
3434
request
3535
.post('/speechTranslate')
3636
.send({
@@ -43,8 +43,8 @@ describe('Validate encoding field', function() {
4343
});
4444
});
4545

46-
describe('Validate sampleRateHertz field', function() {
47-
it('should fail if sampleRateHertz field is missing.', function(done) {
46+
describe('Validate sampleRateHertz field', () => {
47+
it('should fail if sampleRateHertz field is missing.', done => {
4848
request
4949
.post('/speechTranslate')
5050
.send({
@@ -55,7 +55,7 @@ describe('Validate sampleRateHertz field', function() {
5555
})
5656
.expect(400, 'Sample rate hertz must be numeric.', done);
5757
});
58-
it('should fail if sampleRateHertz field is empty.', function(done) {
58+
it('should fail if sampleRateHertz field is empty.', done => {
5959
request
6060
.post('/speechTranslate')
6161
.send({
@@ -66,7 +66,7 @@ describe('Validate sampleRateHertz field', function() {
6666
})
6767
.expect(400, 'Sample rate hertz must be numeric.', done);
6868
});
69-
it('should fail if sampleRateHertz field is not numeric.', function(done) {
69+
it('should fail if sampleRateHertz field is not numeric.', done => {
7070
request
7171
.post('/speechTranslate')
7272
.send({
@@ -79,8 +79,8 @@ describe('Validate sampleRateHertz field', function() {
7979
});
8080
});
8181

82-
describe('Validate languageCode field', function() {
83-
it('should fail if languageCode field is missing.', function(done) {
82+
describe('Validate languageCode field', () => {
83+
it('should fail if languageCode field is missing.', done => {
8484
request
8585
.post('/speechTranslate')
8686
.send({
@@ -91,7 +91,7 @@ describe('Validate languageCode field', function() {
9191
})
9292
.expect(400, 'Invalid language code.', done);
9393
});
94-
it('should fail if languageCode field is empty.', function(done) {
94+
it('should fail if languageCode field is empty.', done => {
9595
request
9696
.post('/speechTranslate')
9797
.send({
@@ -104,8 +104,8 @@ describe('Validate languageCode field', function() {
104104
});
105105
});
106106

107-
describe('Validate audioContent field', function() {
108-
it('should fail if audioContent field is missing.', function(done) {
107+
describe('Validate audioContent field', () => {
108+
it('should fail if audioContent field is missing.', done => {
109109
request
110110
.post('/speechTranslate')
111111
.send({
@@ -116,7 +116,7 @@ describe('Validate audioContent field', function() {
116116
})
117117
.expect(400, 'Invalid audio content.', done);
118118
});
119-
it('should fail if audioContent field is empty.', function(done) {
119+
it('should fail if audioContent field is empty.', done => {
120120
request
121121
.post('/speechTranslate')
122122
.send({

0 commit comments

Comments
 (0)