lobe-editor / rules
Cursor rule180 starsChanged 12 days agoMITView on GitHub
Coding standards and conventions for LobeHub Editor
We split this coding-standards.mdc into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 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.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 22
Use import type / inline type imports for type-only imports.
- Very specific: line 43
Avoid circular imports: pnpm lint:circular (dpdm) fails the pre-commit hook on them.
- Very specific: line 89
Run: pnpm test (watch), pnpm vitest run <path>, pnpm test:coverage.
- Very specific: line 93
Document public props and exported functions with JSDoc.
≈ “Common” is an estimate: at least 1 in 5 of the 6,350 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: Coding standards and conventions for LobeHub Editor
globs: *.ts,*.tsx,*.js,*.jsx
---
# Coding Standards
Lint and format rules are enforced by `eslint.config.js`, `prettier.config.js` and
`stylelint.config.js` (all from `@lobehub/lint`); the pre-commit hook runs them on staged files.
This rule covers conventions the tools do not check.
## TypeScript
- `tsconfig.json` is `strict`; prefer explicit types over `any` in public APIs.
- Public kernel / plugin interfaces live in [src/types/](mdc:src/types/) (`IEditor`,
`IEditorKernel`, `IEditorPlugin`, `IEditorPluginConstructor`, `IServiceID`, ...).
- Naming:
- `I` prefix for service interfaces and their ids: `IMarkdownShortCutService`, `ILitexmlService`.
- `<Name>Props` for React props, `<Name>PluginOptions` / `<Name>Options` for kernel plugin
options, `Serialized<Name>Node` for node JSON.
- Commands are `SCREAMING_SNAKE_CASE` and end with `_COMMAND`.
- Use `import type` / inline `type` imports for type-only imports.
## Imports
```typescript
// External packages first
import { mergeRegister } from '@lexical/utils';
import type { LexicalEditor } from 'lexical';
// Internal modules via the @/ alias (maps to src/)
import { KernelPlugin } from '@/editor-kernel/plugin';
import type { IEditorKernel } from '@/types';
import { createDebugLogger } from '@/utils/debug';
// Relative imports last
import { MyNode } from '../node/MyNode';
import { styles } from './style';
```
- Library code uses `@/…`; demos and docs import the public package names
(`@lobehub/editor`, `@lobehub/editor/react`).
- Avoid circular imports: `pnpm lint:circular` (dpdm) fails the pre-commit hook on them.
## React Components
```tsx
'use client';
import { cx } from '@lobehub/ui';
import type { FC } from 'react';
import { styles } from './style';
import type { MyComponentProps } from './type';
const MyComponent: FC<MyComponentProps> = ({ className, children, ...rest }) => {
return (
<div className={cx(styles.root, className)} {...rest}>
{children}
</div>
);
};
MyComponent.displayName = 'MyComponent';
export default MyComponent;
```
- `FC` + default export + `displayName`. Use `memo` only when it pays off and leave a comment
saying why (`// Keep memo: ...`, see `src/react/Editor/Editor.tsx`).
- Styles in `style.ts` with `createStaticStyles` from `@lobehub/ui` (no CSS files, no
`antd-style` hooks). Details in [react-development](mdc:.cursor/rules/react-development.mdc).
## Kernel Code
- Mutate editor state only inside `editor.update(...)`; command handlers return `true` when
handled.
- Register listeners through `this.register(...)` / `mergeRegister` so they are cleaned up.
- Log with `createDebugLogger` (see [debug-logging](mdc:.cursor/rules/debug-logging.mdc)), not
bare `console.*`; for errors that must always surface use `prodSafeLogger.error`.
## Tests
- Vitest with `globals: true` and the `jsdom` environment (`vitest.config.ts`); import
`describe` / `it` / `expect` / `vi` from `vitest` explicitly.
- Colocate tests in `__tests__/` as `*.test.ts(x)` (a few older folders use `__test__`).
- React tests render with `createRoot` + `act` from React (no Testing Library dependency),
see `src/react/SendButton/__tests__/`.
- Run: `pnpm test` (watch), `pnpm vitest run <path>`, `pnpm test:coverage`.
## JSDoc
Document public props and exported functions with JSDoc; for props include `@default` when
there is one. These comments are the source for the hand-written API tables in `index.mdx`.
## File Naming
- Directories: kebab-case for plugins (`link-highlight`), PascalCase for React component
folders (`src/react/SendButton`).
- Components and React plugins: PascalCase files (`SendButton.tsx`, `ReactHRPlugin.tsx`).
- Nodes: PascalCase (`node/HorizontalRuleNode.ts`).
- Other modules: kebab-case or camelCase, matching neighbouring files (`i-upload-service.ts`,
`registerHotkey.ts`).
- Folder entry is `index.ts`; props in `type.ts`; styles in `style.ts`.
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 3,978 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 repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .cursor/rules/debug-logging.mdcCursor rule
- .cursor/rules/documentation-standards.mdcCursor rule
- .cursor/rules/environment-setup.mdcCursor rule
- .cursor/rules/hotkey-standards.mdcCursor rule
- .cursor/rules/plugin-development.mdcCursor rule
- .cursor/rules/project-structure.mdcCursor rule
- .cursor/rules/react-development.mdcCursor rule
- building-landing-homeSkill
- using-docs-kitSkill
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.

