Skip to content

Conversation

tinaliang
Copy link
Contributor

@tinaliang tinaliang commented Jan 5, 2018

Added eslint rules to each functions sample, refactored code to make each sample eslint compliant.

@tinaliang tinaliang requested a review from inlined January 5, 2018 01:02
Copy link
Member

@inlined inlined left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started glossing over after I got to ~paypal because a lot of feedback was redundant. This sort of change is exactly the kind of thing that we should have been doing in a launch branch. Then we can

  1. Say that we added tslints and package.json mechanically, approve the method and merge
  2. New CLs would tackle a few (or one) code repo at a time which would give you early feedback and each PR could be load balanced between reviewers.

*/

'use strict';
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the spaces on these lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is apparently a known error in Sublime 3. Thanks for catching it!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's still present in this file

// Cache details in the browser for 5 minutes
res.set('Cache-Control', 'private, max-age=300');
res.status(200).json(snapshot.val());
return res.status(200).json(snapshot.val());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? We need the returns here? Also, as a minor nit, I try to promote a more consistent error handling style:

if (uncommonCase) {
  return earlyExit;
}
continueNormalCodeFlow();

So in this case, I'd recommend:

if (snapshot.val() === null) {
  return res.status(404).json({errorCode: 404, errorMessage: `message '${messageId}' not found`});
}
// Cache details in the browser for 5 minutes
return res.set('Cache-Control', 'private, max-age=300');

* limitations under the License.
*/
'use strict';
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still confused why our preambles all got an extra space

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing still

// Return the promise from counterRef.set() so our function
// waits for this async event to complete before it exits.
return collectionRef.once('value')
.then(messagesData => counterRef.set(messagesData.numChildren()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indentation was correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix

else if (!event.data.exists() && event.data.previous.exists()) {
return (current || 0) - 1;
}
// What to do in other cases?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transaction is a subtle API. Returning null means "delete the data here in a transaction" while returning undefined means "abort the transaction".

OTOH, reading through this code it's inefficient because it calls tranaction() even when nothing might need to be done.

Try the following instead:

let increment;
if (event.data.exists() && !event.data.previous.exists()) {
  increment = 1;
} else if (!event.data.exists() && event.data.previous.exists()) {
  increment = -1;
} else {
  return null; // No need to increment or decrement
}

return countRef
  .transaction(current => (current || 0) + increment)
  .then(() => {
    return console.log('Counter updated.');
  });

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we take this ☝️ change?

* limitations under the License.
*/
'use strict';
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaaaaaces

// Create Sharp pipeline for resizing the image and use pipe to read from bucket read stream
const pipeline = sharp();
pipeline
.resize(THUMB_MAX_WIDTH, THUMB_MAX_HEIGHT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These spaces were correct.

* limitations under the License.
*/
'use strict';
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces in this file too

return rp(getProfileOptions);
}
// If error other than auth/user-not-found occurred, fail the whole login process
throw error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I prefer return Promise.reject(error); to keep the original stack trace

// STEP 1: Verify with LINE server that a LINE access token is valid
return rp(verifyTokenOptions)
.then(response => {
.then(response => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.thens indent since they are a line continuation. Multi-line thens continue with the closing bracket of the previous statement.

rp(verifyTokenOptions)
  .then(response => {
  }).then(userRecord => {
  }).then(token => {
  })

@tinaliang tinaliang assigned tinaliang and inlined and unassigned tinaliang Jan 9, 2018
Copy link
Member

@inlined inlined left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: You can view the changes you made without all the boilerplate additions of ESLint files by visiting 40299c3

else if (!event.data.exists() && event.data.previous.exists()) {
return (current || 0) - 1;
}
// What to do in other cases?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we take this ☝️ change?

*/

'use strict';
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's still present in this file

* limitations under the License.
*/
'use strict';
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing still

// Return the promise from counterRef.set() so our function
// waits for this async event to complete before it exits.
return collectionRef.once('value')
.then(messagesData => counterRef.set(messagesData.numChildren()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix

* limitations under the License.
*/
'use strict';
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix spacing

* limitations under the License.
*/
'use strict';
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix spacing in this file

* limitations under the License.
*/
'use strict';
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix

* Returns the list of all users with their ID and lastLogin timestamp.
*/
function getUsers(userIds = [], nextPageToken, accessToken) {
function getUsers(userIds = [], nextPageToken, accessToken) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix

@@ -0,0 +1,113 @@
=== /Users/tinaliang/functions-samples/assistant-say-number/functions ===
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix

console.log('Wrote to:', filePath, 'data:', metadata);
});
});
var result = spawn('identify', ['-verbose', tempLocalFile], { capture: [ 'stdout', 'stderr' ]})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix

@inlined inlined assigned tinaliang and unassigned inlined Jan 10, 2018
@nicolasgarnier
Copy link
Contributor

Can you remove the .DS_Store please?

Copy link
Contributor

@nicolasgarnier nicolasgarnier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI well try to stick to the Google styleguide which uses 4 spaces for line-wrapping: https://google.github.io/styleguide/jsguide.html#formatting-function-expressions

Sometimes automatic formatter fail at indenting this correctly. Also it looks like the auto-formatter is messing with the JSDocs-style comments by removing the heading spaces before the *. I flagged a bunch :)

}).then(() => {
console.log('Counter updated.');
(current || 0) + increment;
}).then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix indentation here (add 2 spaces here and below)

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
admin.initializeApp(functions.config().firebase);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove leading space

console.error('Failure sending notification to', tokens[index], error);
// Cleanup the tokens who are not registered anymore.
if (error.code === 'messaging/invalid-registration-token' ||
error.code === 'messaging/registration-token-not-registered') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add 2 spaces indent here.

return bucket.file(filePath).download({
destination: tempFilePath
}).then(() => {
console.log('Audio downloaded locally to', tempFilePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fixed upstream (I think).
Might be good to do a re-base here :)

* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2016 Google Inc. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add back the heading spaces before the * here?

Same for the other JS Comment in the file

* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2016 Google Inc. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add heading space before * back

* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2017 Google Inc. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add heading space before * back

* See the License for t`he specific language governing permissions and
* limitations under the License.
*/
* Copyright 2017 Google Inc. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add heading space before * back

* If the request method is unsupported (not POST) return a 403 response.
* If an error occurs log the details and return a 500 response.
*/
* Authenticate the provided credentials returning a Firebase custom auth token.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add heading space before * back

* TODO(DEVELOPER): In production you'll need to update this function so that it authenticates with your own credentials system.
* @returns {Promise<boolean>} success or failure.
*/
* Authenticate the provided credentials.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add heading space before * back

@nicolasgarnier
Copy link
Contributor

Are we adding Linting checks as presubmit too? In that case it seems the changes to package.json and firebase.json file changes are missing no?

Copy link
Contributor

@nicolasgarnier nicolasgarnier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there are some indentation issues now: sometimes zero indentation for line-wrap, sometimes 1 space and I saw some 3 spaces. We should fix all this.

else if (!event.data.exists() && event.data.previous.exists()) {
return (current || 0) - 1;
}
(current || 0) + increment;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a return here :)

* Get the Device Tokens for the given user.
*
* @param {string} uid The UID of the user.
* Get the Device Tokens for the given user.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many leading spaces now :P (should be just one)

});
// execute all updates in one go and return the result to end the function
return ref.update(updates);
.onWrite(event => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't need to be changed (the indentation was OK)

.audioFrequency(16000)
.format('flac')
.output(targetTempFilePath);
.setFfmpegPath(ffmpeg_static.path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation looks off here.

.run();
});
};
.on('end', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation looks off here.

Copy link
Contributor Author

@tinaliang tinaliang Feb 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we would want 4 spaces here?

function reencodeAsync(tempFilePath, targetTempFilePath) {
return new Promise((resolve, reject) => {
const command = ffmpeg(tempFilePath)
.setFfmpegPath(ffmpeg_static.path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation looks off here.

},
json: true
});
return rp({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation looks off here looks like we went from 2 spaces to 1 space.

@nicolasgarnier
Copy link
Contributor

PS: I may have done my review before your latest changes so not sure if they all still apply :)

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants