0

I'm using the AirBnb style guide and get an "unexpected use of comma" error here at the end of the first line of code:

  myApp.fields.map(field => (field.obj.label = field.label.default,
    field.label.textContent = field.obj.label));

I can rewrite it to this to remove the error:

  myApp.fields.map(field => field.obj.label = field.label.default);
  myApp.fields.map(field => field.label.textContent = field.obj.label);

https://eslint.org/docs/rules/no-sequences

The way I see the first bit of code that the map loop only runs once of the fields where the second one runs twice.

I can confirm that both parts of the map above are executing and not just the last one. Is there something else I'm missing?

Tristan Forward
  • 3,304
  • 7
  • 35
  • 41

1 Answers1

1

Since you're not transforming the array, you could just use forEach() instead of map(). If you insist on making it into a one-liner, and don't want to violate the no-sequences rule:

myApp.fields.forEach(field => {field.obj.label = field.label.default; field.label.textContent = field.obj.label});

More readable:

myApp.fields.forEach((field) => {
    field.obj.label = field.label.default;
    field.label.textContent = field.obj.label;
});
Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
  • Thanks that works but with it gives error "Expected parentheses around arrow function argument having a body with curly braces. (arrow-parens)". Needs brackets around the field ex. (field), if you want to add that to your answer I'll check it – Tristan Forward Feb 07 '18 at 02:35