Tejas Bhuwania
Tejas Bhuwania

Reputation: 3

How to fix no-param-reassign

The following function shows no-param-reassign error for commitMessageClass.

I wished to know how to solve it. I know I can just close the warning/error in the linter but I need to solve it.

Any ideas?

toggleAllCommitMessagesBody(isActive) {
      this.showAllCommitMessageBody = isActive;

      const toRename = this.showAllCommitMessageBody ? 'commit-message message-body active' : 'commit-message message-body';

      const commitMessageClasses = document.getElementsByClassName('commit-message message-body');
      Array.from(commitMessageClasses).forEach((commitMessageClass) => {
        commitMessageClass.className = toRename;
      });

      this.expandedCommitMessagesCount = isActive ? this.totalCommitMessageBodyCount : 0;
    }

Upvotes: 0

Views: 153

Answers (1)

Gabriel Mangiurea
Gabriel Mangiurea

Reputation: 96

You are mutating the properties (i.e. className property) on the commitMessageClass.

You can use classList.add() to avoid doing that.

Array.from(commitMessageClasses).forEach((commitMessageClass) => {
  commitMessageClass.classList.add(toRename);
});

Upvotes: 1

Related Questions