agentleFS
joaoguimaraesprojoaoguimaraespro/personal-finance/.cursor/rules/csharp-coding-style.mdc

personal-finance / rules

Cursor rule1 starsChanged todayMITView on GitHub

C# coding style: nullable, explicit types, file-scoped namespaces, records, async, formatting

The file

We split this csharp-coding-style.mdc into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Prefer init and constructor parameters.

    line 31
  2. Very specific:

    Every public async method takes a CancellationToken and passes it on.

    line 38

≈ “Common” is an estimate: at least 1 in 5 of the 6,809 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
csharp-coding-style.mdc
---
description: "C# coding style: nullable, explicit types, file-scoped namespaces, records, async, formatting"
globs: **/*.cs,**/*.csx
alwaysApply: false
---
<!-- Generated by armature from stack-dotnet/rules/csharp/coding-style.md. Edit the source rule, not this file. -->
# C# coding style

Extends [common/coding-style.md](common-coding-style.mdc). `.editorconfig` enforces most of this; run
`dotnet format` before committing.

## Language
- Nullable reference types on (`<Nullable>enable</Nullable>`); treat nullable warnings as errors in new projects.
- File-scoped namespaces (`namespace X.Y;`). `using` directives outside the namespace, `System` first, unused removed.
- Braces on every control statement, even one-liners.
- Explicit access modifiers on every non-interface member. `sealed` by default for classes not designed for
  inheritance. `readonly` fields where possible.
- No `dynamic` in application code.

## `var`
The repo's `.editorconfig` (`csharp_style_var_*`) decides (some repos use `var` throughout). When the
repo sets nothing, the default is:
- No `var` for built-in types: `int count = 10;`, `string name = "x";`, `Guid id = Guid.NewGuid();`.
- No `var` when the right side does not make the type obvious (repository calls, LINQ pipelines ending in
  `ToListAsync`, method results): `List<Order> orders = await ...;`, `Order? order = await repo.GetAsync(id, ct);`.
- `var` is fine when the type is apparent: `new Order(...)`, `TimeSpan.FromMinutes(5)`, `Result.Success(x)`.

## Types
- `record` / `record struct` for immutable value-like data (DTOs, requests, responses, value objects); `sealed record`
  for responses. `class` for entities with identity and lifecycle. Interfaces at service boundaries.
- Prefer `init` and constructor parameters; produce changed copies with `with`. Never mutate an input model.
- Primary constructors are fine for dependency injection in services and handlers; keep domain entities with private
  constructors and static factories.
- Money and exact quantities are `decimal`, never `double`/`float`.

## Async
- `async`/`await` all the way; never `.Result`, `.Wait()` or `.GetAwaiter().GetResult()` in request paths.
- Every public async method takes a `CancellationToken` and passes it on. Name async methods `...Async`.
- No `async void` outside event handlers.

## Errors and logging
- Expected failures (not found, validation, conflict, forbidden) are `Result`/`Error` values, not exceptions (see
  [patterns.md](csharp-patterns.mdc)). Exceptions are for the unexpected.
- Structured logging with message templates (`logger.LogError(ex, "Failed to load order {OrderId}", id)`), never
  string interpolation in the template; never log tokens, secrets or personal data.

## Formatting
- Expression-bodied members for properties, accessors, operators and lambdas; block bodies for methods and
  constructors unless a one-line body stays clearly readable.
- LF line endings, 4-space indent, UTF-8, final newline.

<!-- Adapted from affaan-m/ECC rules/csharp/coding-style.md (MIT) at d2ef268 (identical to the Ordo frozen copy); merged with the generic ordo-api CLAUDE.md/.editorconfig conventions (var, braces, file-scoped namespaces, modifiers), personal-finance-sdd (decimal money, primary constructors) and NEXUS knowledge/dotnet. -->

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.