mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/telegramdesktop/tdesktop
synced 2026-09-20 08:03:45 +08:00
[ai] Forbid Q_OS_LINUX checks in the agent guidelines
This commit is contained in:
23
AGENTS.md
23
AGENTS.md
@@ -241,6 +241,29 @@ auto text = u"Settings"_q;
|
|||||||
auto text = QStringLiteral("Settings");
|
auto text = QStringLiteral("Settings");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Never use `Q_OS_LINUX` for platform checks in new code:**
|
||||||
|
|
||||||
|
Telegram Desktop distinguishes at most three platforms: Windows / macOS / all-other. The "all-other" branch covers Linux, the BSD variants and more — and this is almost always the branch you want. `Q_OS_LINUX` narrows it to Linux alone, silently excluding the non-Linux Unix platforms, which is almost never intended. For the all-other branch use `!defined Q_OS_WIN && !defined Q_OS_MAC` at compile time, or its runtime equivalent `Platform::IsLinux()` — which, despite the name, means exactly `!defined Q_OS_WIN && !defined Q_OS_MAC` ("everything except Windows and macOS"), not Linux specifically:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// BAD - excludes FreeBSD and other non-Linux Unix:
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
UnixSpecificCode();
|
||||||
|
#endif // Q_OS_LINUX
|
||||||
|
|
||||||
|
// GOOD - the all-other branch, compile time:
|
||||||
|
#if !defined Q_OS_WIN && !defined Q_OS_MAC
|
||||||
|
UnixSpecificCode();
|
||||||
|
#endif // !Q_OS_WIN && !Q_OS_MAC
|
||||||
|
|
||||||
|
// GOOD - the all-other branch, runtime (same meaning, NOT Linux-only):
|
||||||
|
if (Platform::IsLinux()) {
|
||||||
|
UnixSpecificCode();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`Q_OS_LINUX` is only for the rare case where you genuinely want exactly Linux and not the other Unix-like systems — usually you don't. The few existing uses (`Telegram/SourceFiles/core/sandbox.cpp`, `Telegram/SourceFiles/platform/linux/specific_linux.cpp`) are such genuinely Linux-only code paths and stay as-is.
|
||||||
|
|
||||||
## API Usage
|
## API Usage
|
||||||
|
|
||||||
### API Schema Files
|
### API Schema Files
|
||||||
|
|||||||
21
REVIEW.md
21
REVIEW.md
@@ -553,3 +553,24 @@ Non-static member functions use camelCase (`startBatch`, `finalize`). Static mem
|
|||||||
// GOOD - PascalCase for static method:
|
// GOOD - PascalCase for static method:
|
||||||
[[nodiscard]] static bool ShouldTrack(not_null<HistoryItem*> item);
|
[[nodiscard]] static bool ShouldTrack(not_null<HistoryItem*> item);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## No Q_OS_LINUX platform checks in new code
|
||||||
|
|
||||||
|
Telegram Desktop distinguishes at most three platforms: Windows / macOS / all-other, where "all-other" covers Linux, the BSD variants and more — and this is almost always the branch that is wanted. A `Q_OS_LINUX` check narrows it to Linux alone, silently excluding the non-Linux Unix platforms, which is almost never intended. For the all-other branch use `!defined Q_OS_WIN && !defined Q_OS_MAC` at compile time, or its runtime equivalent `Platform::IsLinux()` — which, despite the name, means exactly `!defined Q_OS_WIN && !defined Q_OS_MAC` ("everything except Windows and macOS"), not Linux specifically. `Q_OS_LINUX` is only for the rare case where exactly Linux is meant and not the other Unix-like systems — usually it is not. The few existing uses (`Telegram/SourceFiles/core/sandbox.cpp`, `Telegram/SourceFiles/platform/linux/specific_linux.cpp`) are such genuinely Linux-only code paths and stay as-is.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// BAD - excludes FreeBSD and other non-Linux Unix:
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
UnixSpecificCode();
|
||||||
|
#endif // Q_OS_LINUX
|
||||||
|
|
||||||
|
// GOOD - the all-other branch, compile time:
|
||||||
|
#if !defined Q_OS_WIN && !defined Q_OS_MAC
|
||||||
|
UnixSpecificCode();
|
||||||
|
#endif // !Q_OS_WIN && !Q_OS_MAC
|
||||||
|
|
||||||
|
// GOOD - the all-other branch, runtime (same meaning, NOT Linux-only):
|
||||||
|
if (Platform::IsLinux()) {
|
||||||
|
UnixSpecificCode();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user