{"filename":"harmony-arkts.mdc","content":"---\ndescription: HarmonyOS ArkTS rules for components, state, resources, layout, lifecycle, and accessibility\nglobs: [\"**/*.ets\", \"**/*.ts\", \"**/*.json5\", \"AppScope/**/*\", \"entry/src/main/**/*\"]\nalwaysApply: false\n---\n\n# HarmonyOS ArkTS Rules\n\n## Component Structure\n\n- Use `@Component` for component definitions and PascalCase for component structs.\n- Keep state declarations near the top of the component.\n- Group lifecycle hooks before `build()`.\n- Place `build()` last and keep it focused on UI composition.\n- Extract complex UI into smaller components.\n\n## State and Data Flow\n\n- Use `@State` for component-owned state.\n- Use `@Prop` for parent-to-child data.\n- Use `@Link` only for intentional two-way binding.\n- Keep derived values in methods or computed helpers rather than duplicating state.\n- Avoid broad global state unless the project has an established app-state pattern.\n\n## Layout and Styling\n\n- Use `Column`, `Row`, `Stack`, `List`, and other ArkUI primitives intentionally.\n- Keep layout properties such as width, height, alignment, and layout weight grouped before visual properties.\n- Use object notation for margin and padding when sides differ.\n- Use logical pixels consistently.\n- Use percentage strings for relative sizes.\n- Keep reusable spacing, colors, and typography in resources when the project supports it.\n\n## Events and Lifecycle\n\n- Use arrow functions for event handlers.\n- Keep event handlers short and delegate complex logic to methods.\n- Handle async failures explicitly and surface user-facing errors where appropriate.\n- Use lifecycle hooks for setup and teardown that genuinely depends on component lifecycle.\n\n## Resources and Accessibility\n\n- Use `$r()` for app resources.\n- Group resource references consistently.\n- Add descriptive labels and focus handling for interactive elements.\n- Maintain color contrast and touch target size.\n- Test on representative device sizes and orientations.\n\n## Common Mistakes\n\n- Do not bury business logic in `build()`.\n- Do not use two-way binding when one-way props are enough.\n- Do not hardcode repeated strings, colors, and dimensions that belong in resources.\n- Do not leave debug `console.log` calls in production code.\n"}