Code Quality Help

Angular / TypeScript Naming Conventions

  • Classes, Interfaces, Types, Enums: PascalCase (e.g., UserProfileComponent, AuthService, OrderStatusEnum).

  • Variables and function/method names: camelCase (e.g., currentUser, calculateDiscount()).

  • Constants: UPPER_SNAKE_CASE (e.g., API_URL, MAX_UPLOAD_SIZE). For local constants that are not exported, camelCase is acceptable.

  • Private fields in classes: camelCase with a leading underscore (e.g., _subscription), or simply camelCase without underscore—choose one and enforce consistently. Recommendation: use underscore for private fields to distinguish from public properties.

  • Observable variables: suffix with $ to indicate asynchronous streams (e.g., user$, data$).

  • Component selectors: kebab-case, prefixed with the project/team prefix (e.g., app-user-list, company-header). No ng- prefix.

  • Directive selectors: camelCase (e.g., [appHighlight]).

  • Enum values: PascalCase (e.g., OrderStatus.Shipped).

Examples:

export interface UserProfile { id: string; displayName: string; } @Component({ selector: 'app-user-profile', templateUrl: './user-profile.component.html' }) export class UserProfileComponent implements OnInit { private subscription = new Subscription(); readonly MAX_NAME_LENGTH = 100; user$: Observable<UserProfile>; constructor(private authService: AuthService) { } ngOnInit(): void { this.user$ = this.authService.currentUser$; } }
04 мая 2026