Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning eslint rule off in eslintrc.json

I am trying to disable jsx-a11y/anchor-is-valid in eslintrc.json. According to the docs, the relevant rule block looks like this:

{
    "rules": {
        "jsx-a11y/anchor-is-valid": [ "error", {
            "components": [ "Link" ],
            "specialLink": [ "hrefLeft", "hrefRight" ],
            "aspects": [ "noHref", "invalidHref", "preferButton" ]
          }]
    }
}

This used to work before I upgraded create-react-app to version 2.0, where my eslint rule was simply "jsx-a11y/anchor-is-valid": 0.

I have read the eslint docs which says that we can simply change error into off, although I have tried that to no avail.

What is the correct way to disable the rule and what is the documentation that I should be referencing?

like image 497
Poh Zi How Avatar asked Oct 02 '18 17:10

Poh Zi How


People also ask

How do I turn off rule in Eslintrc?

1) Disabling "All rules" Two ways you can do this: Put /* eslint-disable-line */ at the end of the line(s), or /* eslint-disable-next-line */ right before the line.

How do I disable ESLint no undef?

You can disable ESLint for a given line using a // eslint-disable-line comment. For example, the below code would cause ESLint to complain because of the no-use-before-define rule if you remove the eslint-disable-line comment. A eslint-disable-line comment disables all ESLint rules for a given line.


1 Answers

Seems like this is a new addition to create react app. The point is to convert the href into a button if possible.

Adding "jsx-a11y/anchor-is-valid": 0 to .eslintrc.json is correct. This prevents errors from showing up when running eslint, but does not prevent errors from showing up in the CRA console.

Alternatives such as // eslint-disable-next-line or href="#/" can be used although perhaps unrecommended. Check out the discussion here for more information.

like image 170
Poh Zi How Avatar answered Sep 26 '22 16:09

Poh Zi How