Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{csproj,props,targets,xml,json,yml}]
indent_style = space
indent_size = 2

[*.cs]
indent_style = space
indent_size = 4

# See CODING_CONVENTIONS.md

# Explicit types, never var
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning
csharp_style_var_elsewhere = false:warning
dotnet_diagnostic.IDE0007.severity = none
dotnet_diagnostic.IDE0008.severity = warning

# Braces always, no single-line if
csharp_prefer_braces = true:warning
dotnet_diagnostic.IDE0011.severity = warning

# No ternary
dotnet_style_prefer_conditional_expression_over_assignment = false:silent
dotnet_style_prefer_conditional_expression_over_return = false:silent
dotnet_diagnostic.IDE0045.severity = none
dotnet_diagnostic.IDE0046.severity = none

# Usings
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false
csharp_using_directive_placement = outside_namespace:warning
dotnet_diagnostic.IDE0005.severity = warning

# Namespaces
csharp_style_namespace_declarations = file_scoped:suggestion

# Allman braces
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true

# Modifiers / this.
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion

# Unused
dotnet_diagnostic.IDE0059.severity = suggestion
dotnet_diagnostic.IDE0060.severity = suggestion
58 changes: 58 additions & 0 deletions CODING_CONVENTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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.
20 changes: 0 additions & 20 deletions CS2-SimpleAdmin-docs/.gitignore

This file was deleted.

41 changes: 0 additions & 41 deletions CS2-SimpleAdmin-docs/README.md

This file was deleted.

Loading