dafthunk / rules
Cursor rule133 starsChanged 9 months agoMITView on GitHub
Use the following format for code blocks: Good Example: React component using Tailwind and shadcn/ui Bad Example: Missing export, bad styling, incorrect file structure Good Example: Test file using Vitest Bad Example: Jest used instead of Vitest When fetching data in React components, use the library SWR (stale-while-revalidate) for its benefits in caching, revalidation, and focus tracking. The primary approach should be to consolidate related data fetching for a view into a single useSWR call. This approach is preferred when:…
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository12 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .cursor/rules/00-persona.mdcCursor rule
- .cursor/rules/01-software-design-guidelines.mdcCursor rule
- .cursor/rules/02-development-environment.mdcCursor rule
- .cursor/rules/03-project-structure.mdcCursor rule
- .cursor/rules/04-code-implementation-guidelines.mdcCursor rule
- .cursor/rules/06-api-development.mdcCursor rule
- .cursor/rules/07-database-development.mdcCursor rule
- .cursor/rules/08-web-routes.mdcCursor rule
- integration-generatorSkill
- node-generatorSkill
- template-generatorSkill
The file
Show its rules and text
We split this 05-web-development.mdc into the rules it gives an agent
20 rules. About 0 are common, 16 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈16
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
- Very specific: line 10
Always write complete, functional components using tsx with a named export function Component.
- Distinctive: line 11
Use Tailwind CSS classes for styling and accessibility best practices.
- Very specific: line 12
Prefer shadcn/ui and lucide-react if appropriate.
- Distinctive: line 13
All code should work in a Vite + React + TypeScript setup.
- Distinctive: line 15
Use Vitest for testing; include test blocks where relevant.
- Very specific: line 16
Use import type when importing types from libraries.
- Distinctive: line 17
Avoid dynamic imports, external APIs, or CDN usage unless requested.
- Distinctive: line 22
Use the following format for code blocks:
- Very specific: line 75
When fetching data in React components, use the library SWR (stale-while-revalidate) for its benefits in caching, revalidation, and focus …
- Distinctive: line 78
All data is necessary for the component to render meaningfully.
- Distinctive: line 137
Avoid by default. Ask: can this logic exist outside React?
- Distinctive: line 138
Always include dependencies.
- Distinctive: line 139
Use an inner async function if needed:
- Distinctive: line 151
Avoid setting derived state inside useEffect.
- Distinctive: line 154
Use only for expensive calculations to avoid unnecessary recalculations.
- Distinctive: line 155
Not needed for simple or fast operations.
- Distinctive: line 168
Use for storing mutable values that persist without triggering re-renders.
- Distinctive: line 170
Don't overuse for general state—it can lead to bugs.
- Distinctive: line 173
Never call hooks inside conditions, loops, or nested functions.
- Distinctive: line 174
Always call hooks at the top level of your component.
≈ “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.
Files
---
description:
globs: apps/web/*
alwaysApply: false
---
# Web application
## Guidelines
1. Always write complete, functional components using `tsx` with a named `export function Component`.
2. Use Tailwind CSS classes for styling and accessibility best practices.
3. Prefer `shadcn/ui` and `lucide-react` if appropriate.
4. All code should work in a Vite + React + TypeScript setup.
5. Include only one file per code block. Avoid multi-file outputs.
6. Use Vitest for testing; include test blocks where relevant.
7. Use `import type` when importing types from libraries.
8. Avoid dynamic imports, external APIs, or CDN usage unless requested.
9. Escaped JSX characters like `<`, `>`, `{`, and `}` must be in string literals.
## Code block structure
Use the following format for code blocks:
```tsx project="ProjectName" file="path/to/file.tsx" type="react"
export function Component() {
// your component here
}
```
## Examples
Good Example: React component using Tailwind and `shadcn/ui`
```tsx project="ButtonExample" file="Button.tsx" type="react"
import { Button } from "@/components/ui/button"
export function Component() {
return <Button className="text-primary">Click me</Button>
}
```
Bad Example: Missing export, bad styling, incorrect file structure
```tsx
function Button() {
return <button style={{ color: 'blue' }}>Click</button>
}
// Missing `export default`
// Uses inline styles instead of Tailwind
// No project/file/type metadata
```
Good Example: Test file using Vitest
```ts project="AddTest" file="add.test.ts" type="code"
import { describe, it, expect } from "vitest"
import { add } from "./add"
describe("add", () => {
it("adds two numbers", () => {
expect(add(2, 3)).toBe(5)
})
})
```
Bad Example: Jest used instead of Vitest
```ts
import { test, expect } from "@jest/globals"
test("adds numbers", () => {
expect(add(2, 3)).toBe(5)
})
// This is incorrect because the project uses Vitest, not Jest
```
## React Loading State Best Practices with SWR
When fetching data in React components, use the library SWR (`stale-while-revalidate`) for its benefits in caching, revalidation, and focus tracking. The primary approach should be to consolidate related data fetching for a view into a single `useSWR` call.
This approach is preferred when:
- All data is necessary for the component to render meaningfully.
- You want a unified loading state for a set of related data.
- Simplicity in state management for data fetching is desired.
Example: Using a single `useSWR` to fetch multiple related resources.
```tsx
import useSWR from 'swr';
export function MyDashboard() {
// The key is an array of the individual resource keys/URLs.
const { data, error, isLoading } = useSWR(
['/api/resourceA', '/api/resourceB'], // Unique keys for SWR
async (keys: [string, string]) => {
const [keyA, keyB] = keys;
const [resourceA, resourceB] = await Promise.all([
fetchResourceA(keyA),
fetchResourceB(keyB),
]);
return { resourceA, resourceB };
};
);
if (isLoading) return <p>Loading dashboard data...</p>;
if (error) return <p>Error loading data: {error.message}</p>;
// data will be { resourceA: {...}, resourceB: {...} }
return (
<div>
<h2>Dashboard</h2>
{data && (
<>
<section>
<h3>Resource A</h3>
<p>{data.resourceA.content}</p>
</section>
<section>
<h3>Resource B</h3>
<p>{data.resourceB.data}</p>
</section>
</>
)}
</div>
);
}
```
By using a single `useSWR` call with a fetcher that handles multiple requests (e.g., via `Promise.all`), you maintain a single `isLoading` and `error` state for the entire set of data required by the view. This simplifies the component logic and provides a more coherent loading experience.
Best Practice:
"Prefer showing meaningful parts of the UI as soon as possible by fetching all necessary data for a view with a single, consolidated `useSWR` call. This avoids janky partial loading and simplifies state management unless specific sections truly require independent data fetching lifecycles."
Avoid:
- Overcomplicating state logic with too many flags.
- Tightly coupling data fetching to UI components.
- Omitting proper error handling and fallback UIs.
## React Hook Usage Best Practices
useEffect:
- Avoid by default. Ask: can this logic exist outside React?
- Always include dependencies; don't silence lint rules.
- Use an inner async function if needed:
```tsx
useEffect(() => {
const load = async () => {
const res = await fetchData()
setData(res)
}
load()
}, [])
```
- Avoid setting derived state inside useEffect. Prefer deriving it during render.
useMemo:
- Use only for expensive calculations to avoid unnecessary recalculations.
- Not needed for simple or fast operations.
```tsx
const filteredItems = useMemo(() => {
return items.filter(i => i.active)
}, [items])
```
useCallback:
- Useful when passing callbacks to memoized child components.
- Prevents unnecessary re-renders due to function identity changes.
useRef:
- Use for storing mutable values that persist without triggering re-renders.
- Useful for DOM element references (e.g., input focus).
- Don't overuse for general state—it can lead to bugs.
General Rules:
- Never call hooks inside conditions, loops, or nested functions.
- Always call hooks at the top level of your component.
- Group and co-locate related hooks to make code easier to read and maintain.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
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.

