Search code examples
angulareslinttypescript-eslint

@angular-eslint/template/eqeqeq Disable or allow null


Using Angular 12 & eslint, I've got an error in the template because I'm doing this:

<button [disabled]="someVariable == null"></button>

Expected === but received == eslint(@angular-eslint/template/eqeqeq)

When going through the source code, I noticed an option called allowNullOrUndefined.

I tried to define the rule like this:

"@angular-eslint/template/eqeqeq": [
    "error",
    {
        "allowNullOrUndefined": true
    }
]

But I still got the error. So I tried to completely disabled the rule, like this:

"@angular-eslint/template/eqeqeq": ["off"]

or like this:

"@angular-eslint/template/eqeqeq": "off"

But with no luck, I still get the error in the template.

I couldn't find any documentation regarding that rule. Can I disable it or allow double equal for null or undefined ?


Solution

  • 2 years later! You were close. Add this to the HTML section of .eslintrc.json like so:

    {
      "files": [
        "*.html"
      ],
      "extends": [
        "plugin:@angular-eslint/template/recommended"
      ],
      "rules": {
        "@angular-eslint/template/eqeqeq": [
          "error",
          {
            "allowNullOrUndefined": true
          }
        ]
      }
    }
    

    Obviously make sure you have the right npm modules installed such as @angular-eslint/template-parser

    These should already be installed if you used ng add @angular-eslint/schematics --skip-confirmation to install eslint into your Angular project.

    NOTE: If a rule includes the string "/template/" then it lives in the HTML section