How to disable multiple rules for eslint nextline

66,749

Solution 1

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

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);
Share:
66,749
shubham choudhary
Author by

shubham choudhary

Updated on May 27, 2021

Comments

  • shubham choudhary
    shubham choudhary over 1 year

    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.

    • jonrsharpe
      jonrsharpe over 3 years
      Why not just => acc + ...? Then you don't break the rules anyway. There's no need for the assignment.
    • shubham choudhary
      shubham choudhary over 3 years
      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
  • Krisztián Balla
    Krisztián Balla about 2 years
    Odd that the eslint-disable (without next-line) only works with the /* ... */ comments and not the // comments.
  • Yannick K about 2 years
    @JennyO'Reilly it is a strange decision from their end indeed. I'll specify it in the answer.
  • paradocslover
    paradocslover almost 2 years
    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.
  • davidjmcclelland
    davidjmcclelland 8 months
    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!