Skip to content

require-explicit-service-contract

Require explicit contracts for classes that invoke retained collaborators.

Why

A one-operation service can orchestrate a collaborator without declaring the contract that callers consume and implementations and fakes satisfy.

Fix

Explicitly implement a focused interface or extend an abstract class covering the service operations. Export the contract only when its consumers need it.

Examples

Before — flagged A single service operation still needs its contract
src/service.ts
class OrchestratorService {
constructor(private readonly worker: Worker) {}
run(): void {
this.worker.run();
}
}
After — preferred The service declares its operation
src/service.ts
interface Runner {
run(): void;
}
class OrchestratorService implements Runner {
constructor(private readonly worker: Worker) {}
run(): void {
this.worker.run();
}
}