Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@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 ?

like image 360
Robouste Avatar asked Sep 11 '25 17:09

Robouste


1 Answers

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

like image 183
danday74 Avatar answered Sep 13 '25 07:09

danday74