Skip to content

require-port-for-service

Advise when an exported service with injected collaborators has public methods not covered by its declared ports.

Why

A declared port keeps consumers coupled to the service capability instead of its concrete implementation.

Fix

Declare and implement an interface covering the service's public methods.

Examples

Before — flagged Do not expose only the concrete service
src/service.ts
export class RequestHandler {
constructor(private readonly store: TaskStore) {}
handle(): void {
this.store.handle();
}
}
After — preferred Implement the service port
src/service.ts
interface Handler {
handle(): void;
}
export class RequestHandler implements Handler {
constructor(private readonly store: TaskStore) {}
handle(): void {
this.store.handle();
}
}

Formerly: require-interface-for-injected-service