Skip to content
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

Merged
merged 12 commits into from
May 13, 2017
Merged

Conversation

DedrickEnc
Copy link
Contributor

@DedrickEnc DedrickEnc commented May 8, 2017

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:

  • Run your code through ESLint. Check out our styleguide.
  • Run integration tests.
  • Run end-to-end tests.
  • Accurately described the changes your are making in this pull request.

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!

@DedrickEnc DedrickEnc requested a review from sfount May 8, 2017 09:29
@sfount
Copy link
Contributor

sfount commented May 8, 2017

This pull request contributes to #1429

@ghost
Copy link

ghost commented May 8, 2017

☔ 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",
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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",
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

@jniles jniles May 11, 2017

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.

@DedrickEnc DedrickEnc force-pushed the linting branch 2 times, most recently from c992faa to 171343a Compare May 12, 2017 14:27
@DedrickEnc
Copy link
Contributor Author

@jniles
Conflicts are fixed

Copy link
Collaborator

@jniles jniles left a 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;
Copy link
Collaborator

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?

@jniles
Copy link
Collaborator

jniles commented May 13, 2017

@kwilu r+

@ghost
Copy link

ghost commented May 13, 2017

📌 Commit 171343a has been approved by jniles

ghost pushed a commit that referenced this pull request May 13, 2017
ghost pushed a commit that referenced this pull request May 13, 2017
Closes: #1612
Approved by: jniles
ghost pushed a commit that referenced this pull request May 13, 2017
Closes: #1612
Approved by: jniles
ghost pushed a commit that referenced this pull request May 13, 2017
Closes: #1612
Approved by: jniles
@ghost
Copy link

ghost commented May 13, 2017

⌛ Testing commit 171343a with merge 5e5a3c8...

ghost pushed a commit that referenced this pull request May 13, 2017
Closes: #1612
Approved by: jniles
ghost pushed a commit that referenced this pull request May 13, 2017
Closes: #1612
Approved by: jniles
ghost pushed a commit that referenced this pull request May 13, 2017
ghost pushed a commit that referenced this pull request May 13, 2017
ghost pushed a commit that referenced this pull request May 13, 2017
Closes: #1612
Approved by: jniles
ghost pushed a commit that referenced this pull request May 13, 2017
ghost pushed a commit that referenced this pull request May 13, 2017
Closes: #1612
Approved by: jniles
ghost pushed a commit that referenced this pull request May 13, 2017
@jniles jniles merged commit cb96f6c into Third-Culture-Software:master May 13, 2017
@DedrickEnc DedrickEnc deleted the linting branch May 15, 2017 09:23
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.

3 participants