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.editorconfigand.gitattributesfiles 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#) andimport(TypeScript) statements must be removed. IDE warnings for unused imports are treated as errors.C# specific: Prefer standard
usingstatements; avoid fully qualified names unless necessary to resolve ambiguity. Useglobal usingfor 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:
Constants and static fields
Instance fields
Public properties
Constructor
Public methods
Private methods Within each group, sort alphabetically or logically.
TypeScript/Angular ordering:
input,@Inputand@Outputdecoratorsinjects
Public properties
Private fields
Constructor
Lifecycle hooks (in execution order:
ngOnInit,ngOnChanges, etc.)Public methods
Private methods
Destroying hooks (
ngOnDestroy)