Disable an ES lint rule - inline

Public, Other Languages

harrylevine

Created: Apr 24, 2017     Updated: Apr 24, 2017


http://eslint.org/docs/user-guide/configuring#disabling-rules-with-inline-comments

The linting error I was receiving was:

Do not mutate state directly. Use setState()

Here is an example of applying the inline disabling of the rule:

// components/nitro_react/app/components/MultiplePhoneNumberInput.jsx

  handleChange = (index) => {
    return (phone_number) => {
      const sanitized = this.sanitizedPhoneNumber(phone_number)
      Object.assign(phone_number, sanitized)

      /* eslint-disable react/no-direct-mutation-state */
      this.state.phoneNumbers[index] = phone_number
      /* eslint-enable react/no-direct-mutation-state */
      this.props.onChange(this.state.phoneNumbers)
    }
  }

The name of the rule being disabled is react/no-direct-mutation-state.

This will cause your linting in Atom, etc., to go from red to green.