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

Add a "return" statement to this callback. #371

Closed
mgmacias95 opened this issue Apr 16, 2019 · 0 comments
Closed

Add a "return" statement to this callback. #371

mgmacias95 opened this issue Apr 16, 2019 · 0 comments
Assignees
Labels

Comments

@mgmacias95
Copy link
Contributor

Arrays in JavaScript have several methods for filtering, mapping or folding that require a callback. Not having a return statement in such a callback function is most likely a mistake.

This rule applies for the following methods of an array:

  • Array.from
  • Array.prototype.every
  • Array.prototype.filter
  • Array.prototype.find
  • Array.prototype.findIndex
  • Array.prototype.map
  • Array.prototype.reduce
  • Array.prototype.reduceRight
  • Array.prototype.some
  • Array.prototype.sort

Noncompliant Code Example:

var merged = arr.reduce(function(a, b) {
  a.concat(b);
}); // Noncompliant: No return statement

Compliant Solution

var merged = arr.reduce(function(a, b) {
  return a.concat(b);
});

if (typeof select_param == 'string') {
select_param.split(',').map(function(x) {
select['fields'].push(x);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants