Is there a way to ignore "Missing return type on function" for Angular lifecycle methods?

Viewed 1848

We're using Angular and I'm trying to switch from tslint to eslint. A rule that throws around 600 warnings is the Missing return type on function from eslint@typescript-eslint/explicit-module-boundary-types.

I do understand that I should use return types for my functions and how to do it. There's virtually no use for lifecycle methods in Angular though. What should I return from ngOnInit?

So the question is: how can I use this rule for every function but not ngOnInit, ngOnDestroy etc?

ngOnInit(): void { // meh
    ...
}

ngOnInit() { // yay
    ...
}

Just in case that it is relevant, my .eslintrc.json:

extends": [
    "plugin:@angular-eslint/recommended",
    "plugin:@angular-eslint/template/process-inline-templates",
    "plugin:@typescript-eslint/recommended",
    "plugin:prettier/recommended"
],
3 Answers

Based on @Ibsn's answer I could come up with this config:

"rules": {
    "@typescript-eslint/explicit-module-boundary-types": [
      "warn",
      {
        "allowedNames": ["ngOnInit", "ngOnDestroy", "ngAfterViewInit", "ngOnChanges"]
      }
    ]
}

There are to ways to solve this problem:

  1. Add before every line with error comment like below to ignore every error in place:
 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types

  1. Just globally ignore this type of errors:
    
    "extends": [
        "plugin:@angular-eslint/recommended",
        "plugin:@angular-eslint/template/process-inline-templates",
        "plugin:@typescript-eslint/recommended",
        "plugin:prettier/recommended"
    ],
    "plugins": ["unused-imports"],
    "rules": {
        "@typescript-eslint/explicit-module-boundary-types": "off"
    }
Related