简体   繁体   English

修复 function 中的无参数重新分配 Eslint 问题

[英]Fixing no-param-reassign Eslint issue in function

With below code, I am getting ESlint error Assignment to property of function parameter 'recurrence' at many places where I // eslint-disable-next-line no-param-reassign disabled the line.使用下面的代码,我在许多地方收到 ESlint 错误Assignment to property of function parameter 'recurrence' // eslint-disable-next-line no-param-reassign disabled the line。 I dont want to use disable.我不想使用禁用。 How so solve this issue without using disable as legit way?如何在不使用禁用作为合法方式的情况下解决这个问题? Can anyone help me with this?谁能帮我这个? THanks谢谢

   onUpdateRecurrence = (recurrence) => {
    const todayDay = moment().format('D');
    const currentMonth = moment().format('M');
    if (recurrence.frequency === 'MONTHLY') {
      if (recurrence.days) {
        // eslint-disable-next-line no-param-reassign
        delete recurrence.days;
      }
      if (recurrence.day_of_month) {
        // eslint-disable-next-line no-param-reassign
        recurrence.day_of_month = recurrence.day_of_month;
      } else {
        // eslint-disable-next-line no-param-reassign
        recurrence.day_of_month = `${todayDay}${this.getDaySuffix(todayDay)}`;
      }
      if (recurrence.month) {
        // eslint-disable-next-line no-param-reassign
        recurrence.month = recurrence.month;
      } else {
        // eslint-disable-next-line no-param-reassign
        recurrence.month = currentMonth;
      }
    }
    if (recurrence.frequency === 'WEEKLY') {
      if (recurrence.day_of_month) {
        // eslint-disable-next-line no-param-reassign
        delete recurrence.day_of_month;
      }
      if (recurrence.month) {
        // eslint-disable-next-line no-param-reassign
        delete recurrence.month;
      }
    }
    if (recurrence.frequency === 'DAILY') {
      if (recurrence.day_of_month) {
        // eslint-disable-next-line no-param-reassign
        delete recurrence.day_of_month;
      }
      if (recurrence.month) {
        // eslint-disable-next-line no-param-reassign
        delete recurrence.month;
      }
      if (recurrence.days) {
        // eslint-disable-next-line no-param-reassign
        delete recurrence.days;
      }
    }
    return recurrence;
  };

You can assign recurrence to a const variable in side the function and use that in side the function.您可以将循环分配给 function 中的const变量,并在 function 中使用它。

 onUpdateRecurrence = (recurrence) => {
    const recurrenceValue = {...recurrence};

   //Your Code
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM