270

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.

2
  • 3
    Why not just => acc + ...? Then you don't break the rules anyway. There's no need for the assignment. Commented Jun 22, 2019 at 9: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 Commented Jun 22, 2019 at 9:58

2 Answers 2

443

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

Sign up to request clarification or add additional context in comments.

4 Comments

Odd that the eslint-disable (without next-line) only works with the /* ... */ comments and not the // comments.
@JennyO'Reilly it is a strange decision from their end indeed. I'll specify it in the answer.
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.
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!
24

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.