Disable an ES lint rule - inline

Public, Other Languages


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


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 */

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.