This rule raises an issue when an Angular lifecycle method is declared but has an empty body with no implementation.

Why is this an issue?

Empty lifecycle methods in Angular components, directives, and services serve no purpose and create unnecessary code clutter. These methods are typically created when implementing lifecycle interfaces like OnInit, OnDestroy, or AfterViewInit, but then left without any implementation.

Empty lifecycle methods can:

Angular will call these methods during the component lifecycle even when they’re empty, which means they consume processing time without providing any value.

What is the potential impact?

While empty lifecycle methods don’t cause runtime errors, they negatively impact code maintainability and can slightly affect performance due to unnecessary method calls during Angular’s lifecycle execution.

How to fix in Angular?

Remove the empty lifecycle method entirely. If you don’t need to implement the lifecycle hook, simply don’t declare the method.

Non-compliant code example

@Component()
class MyComponent implements OnInit {
  ngOnInit() {} // Noncompliant
}

Compliant code example

@Component()
class MyComponent {
  // No ngOnInit method needed if there's no implementation
}

If you plan to implement the method later, add a TODO comment or implement the actual logic immediately.

Non-compliant code example

@Component()
class MyComponent implements OnDestroy {
  ngOnDestroy() {} // Noncompliant
}

Compliant code example

@Component()
class MyComponent implements OnDestroy {
  ngOnDestroy() {
    // Clean up subscriptions
    this.subscription.unsubscribe();
  }
}

Documentation