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

personal-finance / rules

Cursor rule1 starsChanged todayMITView on GitHub

TypeScript and JavaScript coding style: strict types, no any, immutability, errors, validation at the boundary, Biome

The file

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

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    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. Distinctive:

    Follow the repo's choice when it already uses Prettier/ESLint.

    line 14
  2. Very specific:

    Use the repo's package manager (lockfile decides: bun.lock, pnpm-lock.yaml, package-lock.json).

    line 17
  3. Distinctive:

    Never swallow an error: log it with context and rethrow, or turn it into a typed result the caller must handle.

    line 57
  4. Very specific:

    No floating promises: await them, return them, or mark fire-and-forget explicitly with void and a comment.

    line 58

≈ “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
typescript-coding-style.mdc
---
description: "TypeScript and JavaScript coding style: strict types, no any, immutability, errors, validation at the boundary, Biome"
globs: **/*.ts,**/*.tsx,**/*.mts,**/*.cts,**/*.js,**/*.jsx,**/*.mjs
alwaysApply: false
---
<!-- Generated by armature from stack-typescript/rules/typescript/coding-style.md. Edit the source rule, not this file. -->
# TypeScript coding style

## Compiler and tooling

- `strict: true` in every `tsconfig`, plus `noUncheckedIndexedAccess` and `noImplicitOverride` in new projects. Never
  turn a strict flag off to make a build pass.
- One formatter and linter per repo, run by the gate. Default: **Biome** (shared config package in a monorepo).
  Follow the repo's choice when it already uses Prettier/ESLint; never add a second one.
- Suppress a lint finding only on the line, with the tool's own syntax and a reason
  (`// biome-ignore lint/<group>/<rule>: <reason>`). No file-wide disables.
- Use the repo's package manager (lockfile decides: `bun.lock`, `pnpm-lock.yaml`, `package-lock.json`). Never mix.

## Types

- Exported functions, shared utilities and public methods have explicit parameter and return types. Let TypeScript
  infer obvious locals.
- `interface` for object shapes that may be extended; `type` for unions, intersections, tuples, mapped and utility
  types. Prefer string literal unions to `enum`.
- No `any` in application code. Use `unknown` for external input and narrow it; use generics when the type depends on
  the caller.
- No `as` casts that hide a type error and no non-null `!` without a guard on the line above. `satisfies` is the
  way to check a literal against a type without widening it.
- Type-only imports use `import type`.
- In `.js` files that cannot move to TypeScript, use JSDoc types that match runtime behaviour.

```typescript
// WRONG
export function getErrorMessage(error: any) {
  return error.message
}

// CORRECT
export function getErrorMessage(error: unknown): string {
  return error instanceof Error ? error.message : 'Unexpected error'
}
```

## Immutability

Return new objects instead of mutating arguments; mark inputs `Readonly<T>` when it helps.

```typescript
function rename(user: Readonly<User>, name: string): User {
  return { ...user, name }
}
```

## Errors

- `async`/`await` with `try`/`catch`; the caught value is `unknown` and is narrowed before use.
- Never swallow an error: log it with context and rethrow, or turn it into a typed result the caller must handle.
- No floating promises: await them, return them, or mark fire-and-forget explicitly with `void` and a comment.

## Validation at the boundary

Everything that crosses a trust boundary (HTTP bodies, query strings, env vars, `localStorage`, messages from a model
or a tool) is parsed with a schema (Zod or the repo's equivalent) and the type is inferred from the schema.

```typescript
const UserInput = z.object({ email: z.string().email(), age: z.number().int().min(0).max(150) })
type UserInput = z.infer<typeof UserInput>
const input: UserInput = UserInput.parse(body)
```

## Logging

No `console.log` in committed code. Use the repo's logger; never log tokens, secrets or personal data.

## Naming

- Files: kebab-case (`user-card.tsx`) unless the repo's convention differs; one exported component or concept per file.
- Symbols: `PascalCase` types and components, `camelCase` values and functions, `UPPER_SNAKE` for true constants.
- Booleans read as questions: `isLoading`, `hasError`, `canSubmit`.

<!-- Adapted from affaan-m/ECC rules/typescript/coding-style.md and hooks.md (MIT) at d2ef268; merged with the owner's frontend conventions (ordo-frontend CLAUDE.md: strict TS, Biome, bun; personal-finance-sdd typescript-reviewer priorities). -->

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.