Zeus Carl
Zeus Carl

Reputation: 149

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. 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;
  };

Upvotes: 0

Views: 4084

Answers (1)

Nazeer
Nazeer

Reputation: 593

You can assign recurrence to a const variable in side the function and use that in side the function.

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

   //Your Code
 }

Upvotes: 2

Related Questions