summaryrefslogtreecommitdiff
path: root/archived/projt-launcher/docs/contributing/CODE_STYLE.md
blob: b51725a92dda0b99d029da3f8aa92922b0eaec3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# Code Style

Formatting and coding standards for ProjT Launcher.

---

## Formatting

All C++ code must be formatted with clang-format before committing.

```sh
clang-format -i path/to/file.cpp
```

CI will reject unformatted code.

---

## C++ Standards

### Modern C++

| Feature | Usage |
|---------|-------|
| `auto` | Only when type is obvious |
| `nullptr` | Always (never `NULL` or `0`) |
| `override` | Required on all overrides |
| `const` | Required for non-mutating methods |

### Memory Management

**Smart Pointers**:

```cpp
// Good
auto obj = std::make_unique<MyClass>();

// Bad - raw pointer ownership
MyClass* obj = new MyClass();
```

**Qt Parent Ownership**:

```cpp
// Good - Qt manages lifetime
new QButton(this);
```

### Error Handling

- Avoid exceptions
- Use `std::optional` for missing values
- Use `std::expected` for operations that can fail

### Lambdas

```cpp
// Good - explicit capture
connect(btn, &QPushButton::clicked, this, [this, id]() {
    handleClick(id);
});

// Bad - default capture
connect(btn, &QPushButton::clicked, [=]() { ... });
```

---

## Naming Conventions

| Type | Format | Example |
|------|--------|---------|
| Class | PascalCase | `MainWindow` |
| Private member | `m_` + camelCase | `m_currentTheme` |
| Static member | `s_` + camelCase | `s_instance` |
| Public member | camelCase | `dateOfBirth` |
| Constant | SCREAMING_SNAKE | `MAX_VALUE` |
| Function | camelCase | `getCurrentTheme()` || Enum class | PascalCase | `enum class State` |
| Enum values | PascalCase | `State::Running` |

**SCREAMING_SNAKE scope**: Use for `constexpr` constants, `#define` macros, and legacy `enum` values only. Prefer `enum class` with PascalCase values for new code.
---

## Headers

### Include Guards

```cpp
#pragma once
```

### Include Order

1. Corresponding header
2. C++ standard library
3. Qt headers
4. Third-party headers
5. Project headers

```cpp
#include "MyClass.h"

#include <memory>
#include <string>

#include <QObject>
#include <QString>

#include "OtherClass.h"
```

**Note**: clang-format automatically reorders includes. Always accept its output.

### Forward Declarations

Prefer forward declarations over includes when possible:

```cpp
// Good
class OtherClass;

// Avoid
#include "OtherClass.h"
```

**Qt warning**: Forward declarations do not work for QObject-derived classes that use `Q_OBJECT`. These must be fully included.

---

## Comments

### Documentation

```cpp
/// @brief Short description.
///
/// Detailed description if needed.
/// @param input Description of parameter.
/// @return Description of return value.
bool doSomething(const QString& input);
```

### Implementation Comments

```cpp
// Why this approach was chosen
// NOT what the code does
```

### TODOs

```cpp
// TODO(username): Description of what needs to be done
// FIXME(username): Description of broken behavior that needs fixing
```

- **TODO**: Planned improvement or missing feature
- **FIXME**: Known bug or broken behavior requiring attention
- Username is required for traceability
- Compatible with IDE TODO/FIXME highlighting tools

---

## Qt Widgets

### UI Files

- Use Qt Designer for layout
- Never edit generated `ui_*.h` files
- Set meaningful `objectName` values

### Widget Classes

- Keep UI logic minimal
- Delegate to core services
- Use signals/slots for communication

---

## File Templates

These templates apply only to new Project Tick–owned files. Do not modify license headers in upstream forked code.

### Header (.h)

```cpp
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: 2026 Project Tick

#pragma once

#include <QObject>

class MyClass : public QObject {
    Q_OBJECT

public:
    explicit MyClass(QObject* parent = nullptr);
    ~MyClass() override;

signals:
    void somethingHappened();

private:
    QString m_data;
};
```

### Source (.cpp)

```cpp
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: 2026 Project Tick

#include "MyClass.h"

MyClass::MyClass(QObject* parent)
    : QObject(parent)
{
}

MyClass::~MyClass() = default;
```

---

## Related

- [Project Structure](./PROJECT_STRUCTURE.md)
- [Architecture](./ARCHITECTURE.md)