How to disable multiple rules for eslint nextline

JavascriptEslintEslintrc

Javascript Problem Overview


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.

Javascript Solutions


Solution 1 - Javascript

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.)

Solution 2 - Javascript

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);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionshubham choudharyView Question on Stackoverflow
Solution 1 - JavascriptYannick KView Answer on Stackoverflow
Solution 2 - JavascriptVíctor NavarroView Answer on Stackoverflow