# Code Style Policy

> Type: Policy. Rules for the visual structure of production and test code.

## Purpose

Formatting makes the flow of a method and its separate steps visible, helping readers and reviewers focus on behavior. These conventions apply to production and test code; a more specific file contract remains in effect. The scope of an edit follows the [change policy](./change-policy.md).

## Vertical padding

Independent logical steps within a method are separated by one blank line.

A multiline call, object creation, or state declaration forms a visual block. Such a block is followed by an empty line if the next instruction begins another operation rather than continuing the current one.

In production code, separate blocks can be when they are truly separated by meaning:

* receiving or preparing state;
* validation;
* data conversion;
* external call;
* result processing;
* return value.

This list does not specify a mandatory order and does not require artificially creating all phases in each method. Logical grouping is more important than the mechanical rule “empty line after every `);`”.

When a check and its immediate action form one operation, they stay in the same visual block.

## Exceptions

Should not be mechanically changed:

* generated code;
* contents of SQL and string literals;
* fields type/interface/object literals;
* a combination of verification and immediate action;
* short related announcements of one preparatory step.

## Making changes

Bringing existing code to this rule is done in separate style-only commits. In such a change, only empty lines are allowed: you cannot change hyphens, statement order, names, behavior, or refactor at the same time.

Splitting a calculation into variables, extracting a function, and changing branching are refactorings. They are not included in tasks limited to whitespace and line breaks. Preserve evaluation order, short-circuit behavior, and reactive dependencies.

Statement formatting, types, markup, and styles are covered in [Languages and platforms](./languages-and-platforms.md).

## Logical steps in expressions

One statement represents one logical step. Do not combine finding data, accessing the search result, extracting a value, and checking its presence in one expression.

Separate these operations into sequential statements with meaningful names for intermediate variables. Check a result before using it. Preserve existing data guarantees, evaluation order, short-circuit behavior, missing-value behavior, and reactive dependencies.

Multiple calls are acceptable when they express one obvious logical step. Do not split code mechanically by the number of calls. Line length helps formatting but does not make an expression readable by itself.

## Independent operations in methods

A method shows the main flow and the structure of its result. If the details of several independent operations obscure that flow, extract them into meaningfully named functions. Intermediate calculations and variables needed by only one operation stay inside it.

The extraction boundary is a complete task, such as calculating navigation or building a list of links. Do not extract every expression to shorten a method or create chains of trivial helpers. Local decomposition does not itself require a new module or layer.

## Tests

Arrange, Act and Assert are separated by empty lines if they are truly different phases. Related assertions of the same result remain one block.

## Git commit messages

Format: `<type>(<scope>): <short action>`. Scope is indicated when it helps to understand a change.

Valid types:

| Type | When to use it |
| --- | --- |
| `feat` | Adding a new capability |
| `fix` | Fixing a bug |
| `refactor` | Changing code structure without changing its behavior |
| `docs` | Updating documentation |
| `test` | Adding or updating tests |
| `chore` | Project maintenance, such as updating tools or dependencies |

The message is written in English. The description begins with a lowercase letter, uses the imperative form, and does not end with a period or exclamation point. One commit contains one logical change; The message does not list files, tests, hashes, or minor details.
