Home › All rules › Community › Harmony Arkts Cursor Rules

Harmony Arkts Cursor Rules

HarmonyOS ArkTS rules for components, state, resources, layout, lifecycle, and accessibility

CursorAny stackCommunity (CC0)

How to use

Save this as .cursor/rules/harmony-arkts.mdc in your project, commit it, and Cursor will load it. Review it first: community files can be opinionated or out of date.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.cursor/rules/harmony-arkts.mdcDownload  
---
description: HarmonyOS ArkTS rules for components, state, resources, layout, lifecycle, and accessibility
globs: ["**/*.ets", "**/*.ts", "**/*.json5", "AppScope/**/*", "entry/src/main/**/*"]
alwaysApply: false
---

# HarmonyOS ArkTS Rules

## Component Structure

- Use `@Component` for 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 `@State` for component-owned state.
- Use `@Prop` for parent-to-child data.
- Use `@Link` only 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.log` calls in production code.

More: Any stack rules · all community rules

Related rules

Agent safety guardrails Windsurf rules

Always-on Windsurf rules that stop agents from running destructive, costly, or externally visible actions without approval.

WindsurfAny stack

Universal vibe-coding guardrails

Always-on Cursor rules that keep any AI agent careful: plan first, small diffs, verify, never fake it.

CursorAny stack

Prototype-to-production hardening AGENTS.md

AGENTS.md checklist for turning a vibe-coded prototype into a production-ready app: security, data, tests, and ops.

AGENTS.mdAny stack

Ascii Simulation Game Cursor Rules

Cursor rules for ASCII simulation game development.

CursorAny stackCommunity (CC0)

Clean Code Cursor Rules

Guidelines for writing clean, maintainable, and human-readable code. Apply these rules when writing or reviewing code to ensure consistency and quality.

CursorAny stackCommunity (CC0)

Code Guidelines Cursor Rules

Cursor rules for code development with guidelines integration.

CursorAny stackCommunity (CC0)

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.