question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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>
)

eslint@5.16.0 eslint-plugin-react@7.14.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
gitjulcommented, Jun 19, 2020

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

3reactions
nazariydolfincommented, Nov 6, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

disable-next-line doesn't work with react rules in JSX #2369
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.
Read more >
Inline eslint comment in JSX - Stack Overflow
I think this solution will work with 'prettier' code. { // eslint-disable-next-line max-len <Chip ref="code" ...
Read more >
no-console - ESLint - Pluggable JavaScript Linter
This rule disallows calls or assignments to methods of the console object. ... eslint-disable-next-line no-console console.error = function (message) ...
Read more >
User Guide | eslint-plugin-vue
Official ESLint plugin for Vue.js.
Read more >
Introducing JSX - React
It is called JSX, and it is a syntax extension to JavaScript. ... React doesn't require using JSX, but most people find it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found