Cline rules
.clinerules/csharp-guidelines.mdCline rules
Quality
75/100
Scores the file, not the repository.Length
860 words
17 headings · 0 code blocksRepository
1.5k
— · pushed 1 days agoLast changed
3 days ago
First indexed 3 days ago.1# C# Development Guidelines23These guidelines define how to write and modify C# code in this repo.4They apply to both humans and coding agents.56> Note: Some rules are repeated intentionally (Quick rules + Detailed rules) to reduce “agent drift”7> and prevent hallucinated changes. The Detailed rules are the source of truth.89## Quick rules (read first)1011- Use the C# language version configured by the repo/tooling. Do not “upgrade” language features by editing build files.12- Keep changes minimal and scoped to the request. Avoid drive-by refactors and style-only churn.13- Never change these unless explicitly asked to:14 - `global.json`15 - `package.json` / `package-lock.json`16 - `NuGet.config`17- **No reflection in product code** (`/src`). (See “Reflection” section.)18- Follow `.editorconfig` formatting.19- Static fields must be `s_camelCase`. (Match local style for other fields.)20- Prefer ordinal string comparisons for protocol/host/cache keys.21- Nullability: prefer non-nullable, validate at boundaries, use `is null` / `is not null`.22- Tests: MSTest SDK v3 + AAA comments + NSubstitute.2324---2526## General (Detailed rules)2728### Language / tooling29- Prefer modern C# features **when supported by the repo’s configured language version**.30- Do not change `global.json` unless explicitly asked to.31- Do not change repo/tooling versions or build configuration unless explicitly asked.3233### File / dependency hygiene34- Never change these unless explicitly asked to:35 - `global.json`36 - `package.json` / `package-lock.json`37 - `NuGet.config`38- Avoid adding/removing dependencies unless the task explicitly requires it.39- Do not commit build/test artifacts:40 - `bin/`, `obj/`, `TestResults/`, coverage outputs, temporary logs/dumps.4142### “Don’t hallucinate” guardrails (for agents)43- Do not invent new repo conventions. If unsure, follow nearby code patterns.44- Do not introduce new abstractions/helpers unless there is an existing pattern in the repo.45- Prefer small, reviewable commits and changes.4647---4849## Formatting5051- Apply code-formatting style defined in `.editorconfig`.52- Prefer file-scoped namespace declarations (when consistent with the file/project).53- Prefer single-line using directives (when consistent with the file/project).54- Insert a newline before the opening curly brace of any code block:55 - `if`, `for`, `while`, `foreach`, `using`, `try`, `catch`, `finally`, etc.56- Ensure that the final return statement of a method is on its own line.57- Use pattern matching and switch expressions when they improve clarity (do not refactor solely to use them).58- Use `nameof` instead of string literals when referring to member names.5960---6162## Naming & Style6364- Follow naming conventions used in the same file/folder unless explicitly overridden here.6566### Fields67- **Private static fields must be `s_camelCase`** (including `static readonly`).68 - Example: `private static readonly IDictionary<string, string> s_knownHosts = ...;`69- Private instance fields: follow local style (commonly `_camelCase`).7071### Constants72- Use `PascalCase` for constants (unless the file uses a different established convention).7374---7576## Reflection & dynamic code (Product code)7778**Do not use reflection in product code (`/src`)** unless explicitly requested or there is an established existing pattern in the same area that requires it.7980Avoid introducing any of the following in product code:81- `System.Reflection` APIs (e.g., `GetMethod`, `GetProperty`, `Invoke`, `BindingFlags`, etc.)82- `Activator.CreateInstance(...)`83- `Assembly.Load(...)` / dynamic assembly loading84- `dynamic` dispatch used as a substitute for strong typing85- `System.Reflection.Emit` / runtime IL generation8687If an exception is unavoidable (rare):88- Prefer a compile-time alternative first (generics, interfaces, explicit mappings).89- Add a short comment explaining why reflection is required and what alternatives were rejected.90- Keep reflection usage localized and test-covered.9192Reflection is acceptable in:93- Tests, tooling, benchmarks, or dev apps (unless those areas have their own constraints).9495---9697## Nullable Reference Types9899- Declare variables non-nullable by default, and validate `null` at entry points.100- Always use `is null` or `is not null` instead of `== null` or `!= null`.101- Trust C# null annotations and avoid redundant null checks when the type system guarantees non-null.102103---104105## Exceptions & error handling106107- Validate inputs at method boundaries (fail fast).108- Throw the most specific exception type possible:109 - `ArgumentNullException`, `ArgumentException`, `InvalidOperationException`, etc.110- Do not swallow exceptions unless the behavior is expected and documented.111- Do not include secrets/tokens/PII in exception messages or logs.112113---114115## Strings, comparisons, and culture116117- Prefer ordinal comparisons for protocol values, identifiers, hostnames, headers, and cache keys:118 - `StringComparison.Ordinal` / `StringComparison.OrdinalIgnoreCase`119 - `StringComparer.Ordinal` / `StringComparer.OrdinalIgnoreCase`120- Avoid culture-sensitive comparisons unless the string is user-facing (rare in libraries).121122---123124## Documentation125126- Ensure that XML doc comments are created for any public APIs.127 - When applicable, include `<example>` and `<code>` documentation in the comments.128- Public API tracking rules exist in a separate guideline doc—follow that doc when public surface area changes.129130---131132## Testing133134- We use MSTest SDK v3 for tests.135- Emit `// Arrange`, `// Act`, `// Assert` comments.136- Use NSubstitute for mocking in tests.137- Copy existing style in nearby files for test method names and capitalization.138- Prefer deterministic tests (avoid timing flakiness, environment dependence).139140---141142## Running tests143144- To build and run tests in the repo, run `dotnet test`.145 - You need one solution open, or specify the solution explicitly.146- If the repo uses solution-specific or `msbuild` workflows for official validation, follow those.147
Also in AzureAD/microsoft-authentication-library-for-dotnet
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| AzureAD/microsoft-authentication-library-for-dotnet.github/instructions/tests.instructions.md · 1.5k | Copilot instructions | teststylegitdo-not | 62/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-dotnet.clinerules/ai-guidelines.md · 1.5k | Cline rules | no sections | 16/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-dotnet.clinerules/cline-instructions.md · 1.5k | Cline rules | archtypestesting-strategyagent-behaviour | 48/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-dotnet.clinerules/msal-guidelines.md · 1.5k | Cline rules | teststylearchtesting-strategy+3 | 66/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-dotnet.github/instructions/src.instructions.md · 1.5k | Copilot instructions | gitapido-not | 59/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-dotnet.github/copilot-instructions.md · 1.5k | Copilot instructions | setupteststylearch+5 | 47/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| JCodesMore/ai-website-cloner-template.clinerules · 31k | Cline rules | buildlint-formatstylearch+3 | 97/100 | 2 days ago | |
| BryaanF/LiantPortfolio.clinerules/project-guidelines.md · 0 | Cline rules | buildstylearchgit+2 | 96/100 | 3 days ago | |
| lepinkainen/humanlog.clinerules/project-rules.md · 0 | Cline rules | setupbuildtestlint-format+8 | 96/100 | 3 days ago | |
| u9401066/zotero-keeper.clinerules/50-pubmed-project.md · 7 | Cline rules | testlint-formatstylearch+1 | 94/100 | 3 days ago | |
| u9401066/pubmed-search-mcp.clinerules/50-pubmed-project.md · 23 | Cline rules | testlint-formatstylearch+1 | 94/100 | 3 days ago | |
| u9401066/zotero-keepervscode-extension/resources/repo-assets/pubmed-search-mcp/.clinerules/50-pubmed-project.md · 7 | Cline rules | testlint-formatstylearch+1 | 94/100 | 3 days ago | |
| VaillerTeeter/HoshimiNest.clinerules/project-identity.md · 1 | Cline rules | setuparchtypesdo-not | 93/100 | yesterday | |
| blendsdk/codeops-mcp.clinerules/project.md · 0 | Cline rules | buildteststylearch+7 | 91/100 | 3 days ago |
