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

Use default parameters instead of thernary operator #20

Open
fumegalli opened this issue Dec 9, 2022 · 1 comment · May be fixed by #21
Open

Use default parameters instead of thernary operator #20

fumegalli opened this issue Dec 9, 2022 · 1 comment · May be fixed by #21

Comments

@fumegalli
Copy link

Hi,

While using this repository as an example to build my app, I saw an opportunity to contribute cleaning the code.
Default parameters are often cleaner than shorting circuiting (or thernary operator, in this case).

Be aware that if you use default parameters, your function will only provide default values for undefined arguments. Other "falsy" values such as '', "", false, null, 0, and NaN, will not be replaced by a default value.

So, if this is a problem in this case, please, let me know.

Bad:

public clientError (message?: string) {
return BaseController.jsonResponse(this.res, 400, message ? message : 'Unauthorized');
}

Good:

public clientError (message = 'Unauthorized') {
    return BaseController.jsonResponse(this.res, 400, message);
}

Reference:
https://github.com/ryanmcdermott/clean-code-javascript#use-default-parameters-instead-of-short-circuiting-or-conditionals

@fumegalli fumegalli linked a pull request Dec 9, 2022 that will close this issue
@AntennaeVY
Copy link

As an aside, code 400 is Bad Request, not Unauthorized so that should be corrected as well

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 a pull request may close this issue.

2 participants