Code Quality Help

Code Formatting

Consistent formatting eliminates style discussions during code review and makes the code base appear cohesive. The rules in this section are automatically enforced by .editorconfig (C#) and prettier (Angular/TypeScript/SCSS). Any style not covered by these tools is subject to manual review.

4.1 File Encoding and Line Endings

  • Encoding: UTF-8 without BOM (byte order mark) for all source files.

  • Line endings: LF (\n) for TypeScript, SCSS, and HTML; CRLF (\r\n) for C# (Visual Studio default). In cross-platform repositories, the .editorconfig and .gitattributes files must enforce consistency.

4.2 Indentation

  • Indentation style: Spaces, never tabs.

  • Indentation size:

    • C#: 4 spaces.

    • TypeScript, Angular templates: 3 spaces.

    • SCSS, JSON: 2 spaces.

  • Continuation lines: indented by one additional level relative to the parent element.

4.3 Braces and Blocks

  • Braces style: K&R (1TBS). Opening brace on the same line as the statement, closing brace on its own line. Applied consistently across all languages.

    // C# - Good if (condition) { DoSomething(); DoSomething(); } // TypeScript - Good if (condition) { doSomething(); doSomething(); }
  • Do not use braces for single-line statements.

    // Good if (condition) DoSomething(); // Bad if (condition) { DoSomething(); }
  • Empty blocks: Prefer to be written as {} on the same line, but should be consistent per language.

4.4 Line Length and Wrapping

  • Maximum line length: 120 characters. For comments and documentation, the same limit applies.

  • Wrapping: When a line exceeds the limit, break after a comma or before an operator. Parameters should each be on their own line if wrapping is needed.

    public async Task<Order> ProcessAsync(OrderRequest request, CancellationToken tkn) { }

4.5 Whitespace

  • Vertical: One blank line between logical groups of code, after namespaces, between methods and types. No more than one consecutive blank line. File ends with a single blank line.

  • Horizontal:

    • One space after commas and semicolons in control statements.

    • One space around assignment and comparison operators.

    • No space before opening parentheses of method calls or declarations, nor after opening/closing parentheses.

    • No trailing whitespace on any line.

4.6 Using Directives and Imports

  • Ordering (applied via formatter/IDE):

    • System/third-party imports

    • Internal/company imports

    • Local/relative imports

  • Unused: All unused using (C#) and import (TypeScript) statements must be removed. IDE warnings for unused imports are treated as errors.

  • C# specific: Prefer standard using statements; avoid fully qualified names unless necessary to resolve ambiguity. Use global using for commonly used namespaces in modern .NET to keep individual files clean.

4.7 Code Organization within a File

  • General: Place fields, constructors, public members, private members in predictable order.

  • C# ordering:

    1. Constants and static fields

    2. Instance fields

    3. Public properties

    4. Constructor

    5. Public methods

    6. Private methods Within each group, sort alphabetically or logically.

  • TypeScript/Angular ordering:

    1. input, @Input and @Output decorators

    2. injects

    3. Public properties

    4. Private fields

    5. Constructor

    6. Lifecycle hooks (in execution order: ngOnInit, ngOnChanges, etc.)

    7. Public methods

    8. Private methods

    9. Destroying hooks (ngOnDestroy)

06 мая 2026