cs2-SimpleAdmin/CODING_CONVENTIONS.md
Salvatore 460d8b2b85 Migrate menus and votes to Panorama UI Kit
Replace MenuManagerCS2 with Panorama UI Kit for the admin menus and
css_vote. Layout names (menu, vote, banner, toast) are configurable
under MenuConfig and preloaded on startup; MenuType is removed and
ConfigVersion bumped to 26.

- Drop MenuManagerApi.dll and the old chat menu classes
- Reference PanoramaUiKit.Shared.dll, bump CounterStrikeSharp to 1.0.376
- Add .editorconfig and CODING_CONVENTIONS.md, apply them codebase-wide
- Remove the CS2-SimpleAdmin-docs site
- Rewrite README for the fork
2026-10-21 18:51:18 +02:00

58 lines
2.3 KiB
Markdown

# Coding conventions
Rules for all C# in this repository. `.editorconfig` enforces most of them: run
`dotnet format CS2-SimpleAdmin.sln` before committing.
## Types
- Always write the explicit type. No `var`.
```csharp
List<CCSPlayerController> players = Helper.GetValidPlayers();
foreach (CCSPlayerController player in players) { ... }
```
- The only exception is an anonymous type, which has no name (Dapper parameters): `var parameters = new { ... };`.
- Target-typed `new()` and collection expressions (`[]`) are fine: the type is already written on the left.
## Conditions
- No ternary operator (`c ? a : b`). Write an `if`, or extract a small helper that returns.
```csharp
string status = "OFF";
if (loaded)
{
status = "ON";
}
```
- Always use braces, even for one statement. No single-line `if (x) return;`.
- `switch` expressions on a value are fine (`penaltyType switch { ... }`).
- `??` and `?.` are fine.
## Layout
- Allman braces, 4 spaces, LF line endings.
- File-scoped namespaces.
- `using` directives outside the namespace, `System` first, no unused ones.
- Early return to keep nesting shallow.
## Naming
- PascalCase for types, methods, properties, constants. camelCase for locals and parameters. `_camelCase` for private fields.
- A lambda parameter you do not use is `_`. Never assign to a discard (`_ = ...`) inside a lambda whose parameter is `_`: the assignment goes to the parameter.
## Duplication
- When the same expression shows up in several commands, add a helper in `Helper` (see `GetCallerName`,
`GetReasonOrUnknown`, `GetArgsReason`, `GetAdminInfo`, `GetLogName`, `Truncate`, `HasCommandPermission`).
## Comments
- Comment why, not what. No commented-out code: git keeps the history.
- XML `<summary>` on public members and on anything non-obvious.
## UI
- All UI goes through the Panorama UI Kit (`Menus/UiKit.cs`). Never call CounterStrikeSharp chat/center menus directly.
- Menus are built with `MenuBuilder`. A sub-menu returns `builder.WithBackButton()`; the kit draws the back button.
- An option closes the menu after its action, unless it passes `keepOpen: true` or its action opens another menu.
- Panorama does not render chat color tags (`{red}`, `ChatColors`): keep them out of UI text.
- Native calls are not thread-safe: after an `await`, come back with `Server.NextWorldUpdateAsync` before touching the UI.