-
Notifications
You must be signed in to change notification settings - Fork 105
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
Linting the server side code #1612
Conversation
This pull request contributes to #1429 |
☔ The latest upstream changes (presumably 0856853) made this pull request unmergeable. Please resolve the merge conflicts. |
.eslintrc.js
Outdated
"func-names" : "off", | ||
"prefer-arrow-callback" : "off", | ||
"no-underscore-dangle" : "off", | ||
"no-unused-vars" : "off", |
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.
In my experience, this rule is very helpful in cleaning up my code. The only example I can think of that makes it annoying is ExpressJS error handlers, where functions must have arity 4 (and so you might not use next
, but are required to pass it in).
What cases are you finding that it would be useful to turn it off?
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.
In the express, when passing next as parameter but not use that. that why I disabled this.
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.
next
isn't required. The following code is perfectly valid expressjs middleware:
app.get('/route', (req, res) => res.redirect('/other/route'));
If code doesn't use next
, it is confusing to pass it into a function. A better fix would be to simply remove next
from the parameters.
As mentioned about, if it is error handling middleware (which we should only have one), we can just put comment telling ESlint
to ignore that line.
.eslintrc.js
Outdated
"quotes" : ["error", "single", { "allowTemplateLiterals": true }], | ||
"arrow-parens" : "off", | ||
"arrow-body-style" : "off", | ||
"func-names" : "off", |
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.
In my opinion, we should enable func-names
, perhaps with the "as-needed" parameter. Naming a function is better for logs and debugging, which is super helpful in production -- or at least until we have a better logger (like #1519).
I think this should take care of all places that the name cannot be assumed. To understand how Javascript figures out a function name, Dr. Axel Rauschmayer has a really detailed article on 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.
@jniles
I agree, but this rule lead me to even a function which process a promise
.then(function (){
});
produces an error
.then(function someName(){
});
passes but produces an error in the execution
So do you think, I should declare those function on the top of their scopes?
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.
Interesting ... I have never tried .then(function someName() { /* ... */})
before.
It seems to me that callbacks do not need access to this
, so they can be written more easily as arrow functions:
.then((data) => {
// do something without declaring this
});
That way the function's scope is the parent's scope and it behaves like any other code block.
c992faa
to
171343a
Compare
@jniles |
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 still get 456 lint errors, so the server work is not completed, but this is already a huge help!
Code changes look good to me. 👍
@@ -53,7 +53,8 @@ const SQL_STATES = { | |||
* | |||
* This error handler interprets all errors and sends them to the client. | |||
*/ | |||
exports.handler = function handler(error, req, res, next) { | |||
exports.handler = function handler(err, req, res, next) { | |||
let error = err; |
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.
What's going on here?
@kwilu r+ |
📌 Commit 171343a has been approved by |
…inues Closes: #1612 Approved by: jniles
Closes: #1612 Approved by: jniles
Closes: #1612 Approved by: jniles
Closes: #1612 Approved by: jniles
Closes: #1612 Approved by: jniles
Closes: #1612 Approved by: jniles
Closes: #1612 Approved by: jniles
Closes: #1612 Approved by: jniles
Closes: #1612 Approved by: jniles
Closes: #1612 Approved by: jniles
Closes: #1612 Approved by: jniles
Closes: #1612 Approved by: jniles
This PR request amends the code by correcting errors of syntax in most of files in the server side based on the
eslint
rules.Some rule was edited directly in the
.eslintrc.js
references #1429
Thank you for contributing!
Before submitting this pull request, please verify that you have:
For a more detailed checklist, see the official review checklist that this PR will be evaluated against.
Ensuring that the above checkboxes are completed will help speed the review process and help build a stronger application. Thanks!