219

I have this code:

const subTotal = orderInfo.details.reduce((acc, cv) => acc += Number(cv.price) * Number(cv.quantity), 0);

I want to disable two ESLint types of checks for this line, no-return-assign and no-param-reassign.

I tried it this way:

/* eslint-disable-next-line no-return-assign eslint-disable-next-line no-param-reassign */
const subTotal = orderInfo.details.reduce((acc, cv) => acc += Number(cv.price) * Number(cv.quantity), 0);

But my editor is still showing the eslint(no-return-assign) lint error.

Yves M.
  • 29,855
  • 23
  • 108
  • 144
shubham choudhary
  • 2,670
  • 5
  • 13
  • 16
  • 3
    Why not just `=> acc + ...`? Then you don't break the rules anyway. There's no need for the assignment. – jonrsharpe Jun 22 '19 at 09:37
  • 2
    yes, this looks good. Thanks anyways if you know then, just let me know if in any case user wants to disable eslint rule for multiple rules for next line. what can be done in such a case. Is there any way to fix no-return-assign for this case – shubham choudhary Jun 22 '19 at 09:58

2 Answers2

383

If you want to disable multiple ESLint errors, you can do the following (note the commas):

  • For the next line:
// eslint-disable-next-line no-return-assign, no-param-reassign
( your code... )
  • For this line:
( your code... ) // eslint-disable-line no-return-assign, no-param-reassign
  • Or alternatively for an entire code block (note that this only works with multi-line comment syntax):
/* eslint-disable no-return-assign, no-param-reassign */
( your code... )
/* eslint-enable no-return-assign, no-param-reassign */

See the Configuring Rules section of the ESLint documentation.

(Though it might be a better choice to simply disable these errors in your .eslintrc file if you can't follow certain rules all the time.)

Yannick K
  • 4,887
  • 3
  • 11
  • 21
  • 8
    Odd that the `eslint-disable` (without `next-line`) only works with the `/* ... */` comments and not the `//` comments. – Krisztián Balla Oct 10 '20 at 16:52
  • @JennyO'Reilly it is a strange decision from their end indeed. I'll specify it in the answer. – Yannick K Oct 12 '20 at 14:14
  • 3
    For those converting `eslint-disable-next-line` to `eslint-disable` (for multiple lines), remember two things. 1. `/* */` instead of `//` 2. It's `eslint-disable` and not `eslint-disable-next-line`. Just reiterating coz I did the same and had to search many more things due to the 2nd point. May be it's helpful for someone else in the future. – paradocslover Jan 18 '21 at 08:56
  • eslint-*disable* to start exclusion block, eslint-*enable* to end it. Easy to miss this if you put eslint-disable at the end of the block since it will effectively skip the rest of the file! – davidjmcclelland Apr 04 '22 at 18:42
18

You should use commas instead.

/* eslint-disable-next-line no-return-assign, no-param-reassign */
const subTotal = orderInfo.details.reduce((acc, cv) => acc += Number(cv.price) * Number(cv.quantity), 0);
Víctor Navarro
  • 812
  • 9
  • 12