R20BREAKINGfunction

Visibility Narrowed

Flags when a class method's access modifier becomes more restrictive. External consumers or subclasses lose access.


Applies to

TypeScriptJavaRust

Why it matters

Changing public to protected means external callers can no longer access the method. Changing protected to private means subclasses lose access.

Example

Before (public)
// renderer.ts
export class Renderer {
  public render(template: string): string {
    return this.compile(template);
  }
}
After (protected)
// renderer.ts (BREAKING)
export class Renderer {
  protected render(template: string): string {
    return this.compile(template);
  }
}

What you see in the terminal

$ npx dg check

  [BREAKING] render (visibility_changed)
  src/renderer.ts:3
  Method visibility narrowed from 'public' to 'protected'. External callers will lose access.

How detection works

The classifier assigns numeric weights to visibility modifiers (public=1, protected=2, private=3) and checks if the weight increased. If so, access was narrowed.

Real-world scenario

A public method is made protected because the maintainer wants to discourage direct use. However, external consumers still call it.

Edge cases

  • In Go, this is uppercase -> lowercase function name
  • Defaults vary: TypeScript defaults to public, Java to package-private