Eslint-plugin-react: disable-next-line doesn't work with react rules in JSX

Created on 4 Aug 2019  ยท  14Comments  ยท  Source: yannickcr/eslint-plugin-react

When using // eslint-disable-next-line react/jsx-no-bind inside JSX, the violation is not ignored as expected.

Ignoring a built-in rule, e.g. arrow-parens, works as expected (demo). I am only seeing this with react/ rules, like react/jsx-no-bind or react/forbid-dom-props.

To reproduce, lint the following code snippet with

import React from 'react'
const Comp1 = () => null
const Comp2 = () => (
    <Comp1
        key={1}
        // eslint-disable-next-line react/jsx-no-bind
        onChange={isVisible => onChangeVisibility(isVisible, i)}
    ></Comp1>
)

If you move the prop up to be the first prop, it works:

import React from 'react'
const Comp1 = () => null
const Comp2 = () => (
    <Comp1
        // eslint-disable-next-line react/jsx-no-bind
        onChange={isVisible => onChangeVisibility(isVisible, i)}
        key={1}
    ></Comp1>
)

Any other rule works too:

import React from 'react'
const Comp1 = () => null
const Comp2 = () => (
    <Comp1
        key={1}
        // eslint-disable-next-line arrow-parens
        onChange={isVisible => onChangeVisibility(isVisible, i)}
    ></Comp1>
)

[email protected]
[email protected]

bug help wanted

Most helpful comment

I have got the same issue, too. /* eslint-disable */ for multi-line does not work either.

All 14 comments

This seems like more of an issue for eslint itself, not for this plugin - how eslint parses JSX, and override commands, is entirely within eslint's purview.

How come it only happens with react/ rules and not built-in rules?

That's a fair question; it might depend on the rule and what precisely it's warning on. Can you provide an example of core rule jsx overrides that work how you expect?

Yeah, arrow-parens for example. See the issue description for a playground link

ah thanks, sorry i missed that.

It might be some difference in how arrow-parens reports a warning location, versus how eslint-plugin-react does. It seems worth looking into.

I cannot reproduce this bug.

@felixfbecker can you provide npm ls | grep eslint output?

Here ya go:

> yarn list | grep eslint
โ”œโ”€ @sourcegraph/[email protected]
โ”‚  โ”œโ”€ @typescript-eslint/eslint-plugin@^1.13.0
โ”‚  โ”œโ”€ @typescript-eslint/parser@^1.13.0
โ”‚  โ”œโ”€ eslint-config-prettier@^6.0.0
โ”‚  โ”œโ”€ eslint-plugin-ban@^1.2.0
โ”‚  โ”œโ”€ eslint-plugin-etc@^0.0.1-beta.6
โ”‚  โ”œโ”€ eslint-plugin-import@^2.18.2
โ”‚  โ”œโ”€ eslint-plugin-jsdoc@^15.8.0
โ”‚  โ”œโ”€ eslint-plugin-react-hooks@^1.6.1
โ”‚  โ””โ”€ eslint-plugin-react@^7.14.3
โ”œโ”€ @types/[email protected]
โ”œโ”€ @typescript-eslint/[email protected]
โ”‚  โ”œโ”€ @typescript-eslint/[email protected]
โ”‚  โ”œโ”€ eslint-utils@^1.3.1
โ”œโ”€ @typescript-eslint/[email protected]
โ”‚  โ”œโ”€ @typescript-eslint/[email protected]
โ”‚  โ””โ”€ eslint-scope@^4.0.0
โ”œโ”€ @typescript-eslint/[email protected]
โ”‚  โ”œโ”€ @types/eslint-visitor-keys@^1.0.0
โ”‚  โ”œโ”€ @typescript-eslint/[email protected]
โ”‚  โ”œโ”€ @typescript-eslint/[email protected]
โ”‚  โ””โ”€ eslint-visitor-keys@^1.0.0
โ”œโ”€ @typescript-eslint/[email protected]
โ”‚  โ”œโ”€ [email protected]
โ”‚  โ”œโ”€ [email protected]
โ”‚  โ”œโ”€ [email protected]
โ”‚  โ”œโ”€ [email protected]
โ”‚  โ”œโ”€ [email protected]
โ”‚  โ”‚  โ”œโ”€ eslint-scope@^4.0.3
โ”‚  โ”‚  โ”œโ”€ eslint-utils@^1.3.1
โ”‚  โ”‚  โ”œโ”€ eslint-visitor-keys@^1.0.0
โ”‚  โ”‚  โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”‚  โ”œโ”€ eslint-etc@^0.0.1
โ”œโ”€ [email protected]
โ”‚  โ”œโ”€ eslint-import-resolver-node@^0.3.2
โ”‚  โ”œโ”€ eslint-module-utils@^2.4.0
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”‚  โ”œโ”€ eslint@^3.7.1
โ”‚  โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”‚  โ””โ”€ eslint-visitor-keys@^1.0.0
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”‚  โ”œโ”€ eslint-scope@^5.0.0
โ”‚  โ”œโ”€ [email protected]
โ”‚  โ”œโ”€ eslint-utils@^1.4.2
โ”‚  โ”œโ”€ eslint-visitor-keys@^1.1.0
โ”‚  โ”‚  โ””โ”€ eslint-visitor-keys@^1.1.0
โ”‚  โ””โ”€ eslint-visitor-keys@^1.0.0
โ”‚  โ”œโ”€ eslint-scope@^4.0.3

Failure seen just now:

image

I'm having the same issue.

image

image

@cmrigney in your case, you're ensuring that renderRow will be !== on successive renders, breaking any PureComponent-like optimizations in RenderOption.

I have got the same issue, too. /* eslint-disable */ for multi-line does not work either.

this is a bit stale, but since it's not closed, and in case anyone else runs into this thread, have you tried surrounding the rule in brackets, e.g. { /* eslint-disable-next-line react/jsx-no-bind */ }?

could look like this:

<Comp1
  { /* eslint-disable-next-line react/jsx-no-bind */ }
  onChange={isVisible => onChangeVisibility(isVisible, i)}
  key={1}
></Comp1>

or this:

<Comp1
  onChange={isVisible => onChangeVisibility(isVisible, i)}   { /* eslint-disable-line react/jsx-no-bind */ }
  key={1}
></Comp1>

I just did something like that in a project after being stuck for a while and it worked.
found the solution here: https://github.com/eslint/eslint/issues/7030

Code:

const MenuItem = ({title, imageUrl, size}) => (
    <div className ={'${size}, menu-item'}>

      <div className='background-image'style={{backgroundImage: 'url(${imageUrl})'}}>

        </div>
    <div className='content'>
        <h1 className='title'>{title.toUpperCase()}</h1>
        <span className='sub-title'>Shop Now</span>
    </div>
</div>
)

Issue:
```sh
/components/menu-item/menu-item.component.jsx
Line 5:22: Unexpected template string expression no-template-curly-in-string
Line 7:65: Unexpected template string expression no-template-curly-in-string

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
```
Having an issue image is not loading

@ManoharSomu your problem is entirely unrelated to this issue. You're not using template literals, which only use backticks.

Was this page helpful?
0 / 5 - 0 ratings