14

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?

2
  • "off" should be correct as far as I know. Are you leaving the Object after the "off" or are you just leaving the literal: "jsx-a11y/anchor-is-valid": [ "off"]?
    – zero298
    Oct 2, 2018 at 17:30
  • hi @zero298, thank you for the reply. I've tried ["off"], "off", ["off", {}]
    – Poh Zi How
    Oct 2, 2018 at 17:37

1 Answer 1

19

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.