harmony arkts
via PatrickJS/awesome-cursorrules
HarmonyOS ArkTS component, state, layout, and accessibility patterns for robust UI development.
What is harmony arkts?
Establishes conventions for ArkTS component structure, state management, layout composition, and lifecycle handling in HarmonyOS projects. Use this rule to maintain consistent component architecture, proper data flow, and accessibility standards across your ArkTS codebase.
- Enforce @Component structure with PascalCase naming, state declarations at top, and build() last
- Guide state management using @State, @Prop, and @Link with clear ownership and data flow patterns
- Organize layout properties (width, height, alignment) before visual properties using ArkUI primitives
- Handle events with arrow functions and delegate complex logic to methods; manage async failures explicitly
- Use $r() for app resources and maintain color contrast, focus handling, and touch target sizes for accessibility
- Prevent common mistakes: no business logic in build(), no hardcoded strings/colors/dimensions, no debug logs in production
Applies to
File patterns this rule matches.
Rule definition (reference)
Source of truth, from the repository.
HarmonyOS ArkTS Rules
Component Structure
- Use
@Componentfor component definitions and PascalCase for component structs. - Keep state declarations near the top of the component.
- Group lifecycle hooks before
build(). - Place
build()last and keep it focused on UI composition. - Extract complex UI into smaller components.
State and Data Flow
- Use
@Statefor component-owned state. - Use
@Propfor parent-to-child data. - Use
@Linkonly for intentional two-way binding. - Keep derived values in methods or computed helpers rather than duplicating state.
- Avoid broad global state unless the project has an established app-state pattern.
Layout and Styling
- Use
Column,Row,Stack,List, and other ArkUI primitives intentionally. - Keep layout properties such as width, height, alignment, and layout weight grouped before visual properties.
- Use object notation for margin and padding when sides differ.
- Use logical pixels consistently.
- Use percentage strings for relative sizes.
- Keep reusable spacing, colors, and typography in resources when the project supports it.
Events and Lifecycle
- Use arrow functions for event handlers.
- Keep event handlers short and delegate complex logic to methods.
- Handle async failures explicitly and surface user-facing errors where appropriate.
- Use lifecycle hooks for setup and teardown that genuinely depends on component lifecycle.
Resources and Accessibility
- Use
$r()for app resources. - Group resource references consistently.
- Add descriptive labels and focus handling for interactive elements.
- Maintain color contrast and touch target size.
- Test on representative device sizes and orientations.
Common Mistakes
- Do not bury business logic in
build(). - Do not use two-way binding when one-way props are enough.
- Do not hardcode repeated strings, colors, and dimensions that belong in resources.
- Do not leave debug
console.logcalls in production code.
Related rules
Senior full-stack TypeScript, React, Node.js guidance with clean architecture, testing, and WHY-oriented reasoning.
Quantitative factor research skills for designing, evaluating, and mining alpha factors in equities markets.
Android development with Jetpack Compose, clean architecture, and Material Design 3.
Angular development with Novo Elements UI library using standalone components.
Expert Angular 18 + TypeScript development with Jest, emphasizing clean code and performance.
Manage Kubernetes clusters, add-ons, stacks, and credentials via the Ankra CLI platform.