-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Eslintcompliant #306
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
Eslintcompliant #306
Conversation
There was a problem hiding this 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
- Say that we added tslints and package.json mechanically, approve the method and merge
- 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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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');
child-count/functions/index.js
Outdated
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
'use strict'; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indentation was correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix
child-count/functions/index.js
Outdated
else if (!event.data.exists() && event.data.previous.exists()) { | ||
return (current || 0) - 1; | ||
} | ||
// What to do in other cases? |
There was a problem hiding this comment.
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.');
});
There was a problem hiding this comment.
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?
image-sharp/functions/index.js
Outdated
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
'use strict'; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These spaces were correct.
instagram-auth/functions/index.js
Outdated
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
'use strict'; |
There was a problem hiding this comment.
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
line-auth/functions/index.js
Outdated
return rp(getProfileOptions); | ||
} | ||
// If error other than auth/user-not-found occurred, fail the whole login process | ||
throw error; |
There was a problem hiding this comment.
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
line-auth/functions/index.js
Outdated
// STEP 1: Verify with LINE server that a LINE access token is valid | ||
return rp(verifyTokenOptions) | ||
.then(response => { | ||
.then(response => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.then
s indent since they are a line continuation. Multi-line then
s continue with the closing bracket of the previous statement.
rp(verifyTokenOptions)
.then(response => {
}).then(userRecord => {
}).then(token => {
})
There was a problem hiding this 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
child-count/functions/index.js
Outdated
else if (!event.data.exists() && event.data.previous.exists()) { | ||
return (current || 0) - 1; | ||
} | ||
// What to do in other cases? |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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
child-count/functions/index.js
Outdated
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
'use strict'; |
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix
convert-images/functions/index.js
Outdated
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
'use strict'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix
eslint_results.txt
Outdated
@@ -0,0 +1,113 @@ | |||
=== /Users/tinaliang/functions-samples/assistant-say-number/functions === |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix
exif-images/functions/index.js
Outdated
console.log('Wrote to:', filePath, 'data:', metadata); | ||
}); | ||
}); | ||
var result = spawn('identify', ['-verbose', tempLocalFile], { capture: [ 'stdout', 'stderr' ]}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix
Can you remove the |
There was a problem hiding this 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 :)
child-count/functions/index.js
Outdated
}).then(() => { | ||
console.log('Counter updated.'); | ||
(current || 0) + increment; | ||
}).then(() => { |
There was a problem hiding this comment.
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)
child-count/functions/index.js
Outdated
const functions = require('firebase-functions'); | ||
const admin = require('firebase-admin'); | ||
admin.initializeApp(functions.config().firebase); | ||
admin.initializeApp(functions.config().firebase); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove leading space
fcm-notifications/functions/index.js
Outdated
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') { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 :)
github-to-slack/functions/index.js
Outdated
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
* Copyright 2016 Google Inc. All Rights Reserved. |
There was a problem hiding this comment.
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
text-moderation/functions/index.js
Outdated
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
* Copyright 2016 Google Inc. All Rights Reserved. |
There was a problem hiding this comment.
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
url-shortener/functions/index.js
Outdated
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
* Copyright 2017 Google Inc. All Rights Reserved. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
Are we adding Linting checks as presubmit too? In that case it seems the changes to |
There was a problem hiding this 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.
child-count/functions/index.js
Outdated
else if (!event.data.exists() && event.data.previous.exists()) { | ||
return (current || 0) - 1; | ||
} | ||
(current || 0) + increment; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation looks off here.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation looks off here.
github-to-slack/functions/index.js
Outdated
}, | ||
json: true | ||
}); | ||
return rp({ |
There was a problem hiding this comment.
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.
PS: I may have done my review before your latest changes so not sure if they all still apply :) |
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 |
b408451
to
1daacbe
Compare
68fe5e0
to
c157cd4
Compare
Added eslint rules to each functions sample, refactored code to make each sample eslint compliant.