@lark-apaas/coding-steering 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/coding-steering",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Stack-specific steering content for miaoda-coding templates",
5
5
  "type": "module",
6
6
  "files": ["steering"],
@@ -1,40 +0,0 @@
1
- ---
2
- name: react-hook-best-practices
3
- description: "Use when writing or reviewing React hooks: useEffect dependencies, useMemo/useCallback, custom hooks. 触发词:useEffect, useMemo, useCallback, 自定义 hook, React hook 规范"
4
- steering: true
5
- steering-topic: react_hook_best_practices
6
- ---
7
-
8
- # React Hook 最佳实践
9
-
10
- ## 一、useEffect 依赖
11
-
12
- ```tsx
13
- // ❌ 错:缺依赖
14
- useEffect(() => {
15
- fetchUser(userId);
16
- }, []);
17
-
18
- // ✅ 对:完整依赖
19
- useEffect(() => {
20
- fetchUser(userId);
21
- }, [userId]);
22
- ```
23
-
24
- - 始终用 `eslint-plugin-react-hooks` 自动检查依赖
25
- - 不要为了"避免重复执行"省略依赖——用 cleanup function 或 ref 处理
26
-
27
- ## 二、useMemo / useCallback
28
-
29
- 只在以下场景使用:
30
-
31
- - 计算昂贵(实测 >5ms)
32
- - 引用稳定性影响下游(passed as prop to memoized child)
33
-
34
- 默认**不预先优化**——大多数计算不需要 memo。
35
-
36
- ## 三、自定义 hook
37
-
38
- - 命名以 `use` 开头:`useDebounce` / `useLocalStorage`
39
- - 单一职责,<50 行
40
- - 内部不直接操作 DOM(用 ref + useEffect)
@@ -1,36 +0,0 @@
1
- ---
2
- name: tailwind-conventions
3
- description: "Use when styling components with Tailwind CSS: class organization, custom utilities, dark mode, responsive design. 触发词:Tailwind, className 顺序, 暗色模式, 响应式设计"
4
- steering: true
5
- steering-topic: tailwind_conventions
6
- ---
7
-
8
- # Tailwind 约定
9
-
10
- ## 一、className 顺序
11
-
12
- 按下列顺序写 class:
13
-
14
- 1. layout(display / position / flex / grid)
15
- 2. spacing(margin / padding / gap)
16
- 3. sizing(width / height)
17
- 4. typography(text-* / font-*)
18
- 5. color(bg-* / text-* / border-*)
19
- 6. interactive(hover: / focus: / active:)
20
- 7. responsive(md: / lg:)
21
-
22
- ```tsx
23
- <div className="flex items-center gap-2 px-4 py-2 text-sm text-gray-900 bg-white hover:bg-gray-50 md:px-6">
24
- ```
25
-
26
- ## 二、暗色模式
27
-
28
- - 用 `next-themes` 提供 `dark` class 切换
29
- - 颜色用 `bg-white dark:bg-gray-900` 双写
30
-
31
- ## 三、避免硬编码颜色
32
-
33
- ❌ `text-[#3b82f6]`
34
- ✅ `text-blue-500`
35
-
36
- 如确需自定义色,加到 `tailwind.config.js` 的 theme.colors。
@@ -1,48 +0,0 @@
1
- ---
2
- name: client-coding-guide
3
- description: "Use when implementing client-side features in vite-react stack: components, hooks, routing, state management. 触发词:客户端开发, React 组件, 页面路由, hooks, vite, vite-react"
4
- steering: true
5
- steering-topic: client_coding_guide
6
- ---
7
-
8
- # Client Coding Guide (vite-react)
9
-
10
- ## 一、组件分层
11
-
12
- ```
13
- ui/ ← shadcn-ui 基础组件,源码自动生成,禁止直接编辑
14
- components/ ← 业务组件,组合 ui/ 实现具体场景
15
- pages/ ← 路由页面,组合多个 components/ 构建完整界面
16
- ```
17
-
18
- ## 二、State 管理
19
-
20
- - 局部 state 用 `useState`
21
- - 共享 state 优先用 React Context
22
- - 避免引入 Redux/Zustand 等全局 store(v0.1 不依赖)
23
-
24
- ## 三、表单实现模板
25
-
26
- ```tsx
27
- import { useForm } from 'react-hook-form';
28
- import { zodResolver } from '@hookform/resolvers/zod';
29
- import { z } from 'zod';
30
-
31
- const schema = z.object({
32
- name: z.string().min(1, '必填'),
33
- email: z.string().email(),
34
- });
35
-
36
- type FormValues = z.infer<typeof schema>;
37
-
38
- export function MyForm() {
39
- const form = useForm<FormValues>({ resolver: zodResolver(schema) });
40
- const onSubmit = (values: FormValues) => { /* ... */ };
41
- return (
42
- <form onSubmit={form.handleSubmit(onSubmit)}>
43
- <input {...form.register('name')} />
44
- {/* ... */}
45
- </form>
46
- );
47
- }
48
- ```
@@ -1,48 +0,0 @@
1
- ---
2
- name: component-conventions
3
- description: "Use when creating or refactoring React components: naming, file structure, props typing, default values. 触发词:组件命名, props 类型, 组件文件结构, React 最佳实践"
4
- steering: true
5
- steering-topic: component_conventions
6
- ---
7
-
8
- # Component Conventions (vite-react)
9
-
10
- ## 一、文件结构
11
-
12
- 每个组件一个目录:
13
-
14
- ```
15
- components/
16
- └── UserCard/
17
- ├── index.tsx # 组件主文件
18
- ├── UserCard.test.tsx # 测试(可选)
19
- └── types.ts # 局部类型(可选)
20
- ```
21
-
22
- ## 二、命名
23
-
24
- - 组件名 PascalCase:`UserCard`、`StatusBadge`
25
- - 文件名跟组件名一致:`UserCard.tsx`
26
- - props 接口:`UserCardProps`
27
-
28
- ## 三、props 类型
29
-
30
- ```tsx
31
- interface UserCardProps {
32
- user: User;
33
- onSelect?: (id: string) => void;
34
- className?: string;
35
- }
36
-
37
- export function UserCard({ user, onSelect, className }: UserCardProps) {
38
- // ...
39
- }
40
- ```
41
-
42
- - **强制带 `className?: string`**——所有业务组件都应允许外部传 className
43
- - **回调用 `onXxx` 命名**——`onSelect` / `onChange` / `onSubmit`
44
-
45
- ## 四、默认导出 vs 命名导出
46
-
47
- - 业务组件**命名导出**:`export function UserCard ...`
48
- - 入口/页面组件可以默认导出