agentleFS
PostHogKnown publisherPostHog/posthog-foss/.cursor/rules/react-typescript.mdc

posthog-foss / rules

Cursor rule721 starsChanged 56 days agoMITView on GitHub

Rules for writing frontend code at PostHog (mostly React + Typescript with Kea)

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

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

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈15

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Always implement data layer in Kea logic.

    line 17
  2. Distinctive:

    Write TypeScript with proper typing for all new code

    line 20
  3. Distinctive:

    Use functional programming patterns.

    line 21
  4. Distinctive:

    Prefer iteration and modularization over code duplication.

    line 22
  5. Distinctive:

    Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).

    line 23
  6. Very specific:

    Don't use useState or useEffect to store local state.

    line 24
  7. Distinctive:

    Use named exports; avoid default exports

    line 26
  8. Very specific:

    Always look around the codebase for naming conventions, and follow the best practices of the environment (e.g.

    line 30
  9. Very specific:

    Use clear, yet functional names (searchResults vs data).

    line 31
  10. Very specific:

    Avoid index.ts, styles.css, and other generic names, even if this is the only file in a directory.

    line 36
  11. Distinctive:

    Use Tailwind CSS as primary styling solution

    line 39
  12. Distinctive:

    Use SCSS with component-specific files

    line 41
  13. Distinctive:

    Follow BEM for modals (.DashboardMenu__modal)

    line 43
  14. Distinctive:

    Import styles directly (MyComponent.scss)

    line 44
  15. Distinctive:

    When mentioning PostHog products, the product names should use Sentence casing, not Title Casing.

    line 46
  16. Distinctive:

    Add presentational elements to Storybook

    line 51
  17. Distinctive:

    Run storybook locally: pnpm storybook

    line 52
  18. Distinctive:

    Keep data layer separate from view hierarchy

    line 56
  19. Distinctive:

    Write clear, understandable code

    line 57

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 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
react-typescript.mdc
---
description: Rules for writing frontend code at PostHog (mostly React + Typescript with Kea)
globs: frontend/**/*.ts,frontend/**/*.tsx,products/**/*.ts,products/**/*.tsx
alwaysApply: false
---

You are an expert in TypeScript, React, Kea, Tailwind, and UX design.

Since you are an expert, remember that when you add or remove anything in a kea *logic.ts file there will always be typescript errors.

You need to wait for the kea typegen to complete before those errors go away, please don't start editing files trying to fix the errors until kea typegen has run

Also, any file with a name ending logicType.ts is autogenerated and should never be edited

Architecture
  - Two-layer system: Kea (data/state) -> React (view/template)
  - Always implement data layer in Kea logic; avoid React state

Code Style and Structure
  - Write TypeScript with proper typing for all new code
  - Use functional programming patterns; avoid classes
  - Prefer iteration and modularization over code duplication.
  - Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
  - Don't use `useState` or `useEffect` to store local state. It's false convenience. Take the extra 3 minutes and change it to a `logic` early on in the development.
  - Logics still have a tiny initialization cost. Hence this rule doesn't apply to library components in the `lib/` folder, which might be rendered hundreds of times on a page with different sets of data. Still feel free to write a logic for a complicated `lib/` component when needed.
  - Use named exports; avoid default exports
  - Structure files logically: logic, component, types, styles

Naming Conventions
  - Always look around the codebase for naming conventions, and follow the best practices of the environment (e.g. use `camelCase` variables in JS, `snake_case` in Python).
  - Use clear, yet functional names (`searchResults` vs `data`).
  - Logics are camelCase (`dashboardLogic`)
  - React components are PascalCase (`DashboardMenu`).
  - Props for both logics and components are PascalCase and end with `Props` (`DashboardLogicProps` & `DashboardMenuProps`)
  - Name the `.ts` file according to its main export: `DashboardMenu.ts` or `DashboardMenu.tsx` or `dashboardLogic.ts` or `Dashboard.scss`. Pay attention to the case.
  - Avoid `index.ts`, `styles.css`, and other generic names, even if this is the only file in a directory.

UI and Styling
  - Use Tailwind CSS as primary styling solution
  - For non-Tailwind cases:
    - Use SCSS with component-specific files
    - Namespace under component class (.DashboardMenu)
    - Follow BEM for modals (.DashboardMenu__modal)
    - Import styles directly (MyComponent.scss)
  - Replace custom SCSS with Tailwind when possible
  - When mentioning PostHog products, the product names should use Sentence casing, not Title Casing. For example, 'Product analytics', not 'Product Analytics'. Any other buttons, tab text, tooltips, etc should also all use Sentence casing. For example, 'Save as view' instead of 'Save As View'.

Testing Requirements
  - Logic tests for all Kea logic files
  - React Testing Library tests for interactive lib/ components
  - Add presentational elements to Storybook
  - Run storybook locally: pnpm storybook

Core Principles
  - Prioritize maintainability over development speed
  - Keep data layer separate from view hierarchy
  - Write clear, understandable code
  - Think data first, implement views second

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.