white-label
white-label copied to clipboard
Use default parameters instead of thernary operator
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: https://github.com/stemmlerjs/white-label/blob/503ee491192a3eff026704f4de9a7477daebb630/src/core/infra/BaseController.ts#L34-L36
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
As an aside, code 400 is Bad Request, not Unauthorized so that should be corrected as well