Rule
0 installs · 0 said it worked
HarmonyOS ArkTS coding rules for components, state, and layout
Cursor rules guiding code generation for HarmonyOS ArkTS: component structure, state and data flow, layout and styling, events, resources, and accessibility.
People use this for
- harmonyos arkts coding rules
- arkts component state layout guidelines
- arkui state management best practices
- harmonyos app code generation rules
- arkts cursor rules for developers
- Name
harmonyos-arkts-coding-rules-for-components-state-and-layout- Works with
- Cursor
- License
- CC0(as observed at the source)
- Version
- v1 · updated Nov 29, 2026
Imported on Nov 29, 2026 from github.com . License observed at the source on Nov 29, 2026: CC0.
Are you the author?Claim this profileRequest removal
Use this rule
$ curl -fsSL "https://promptcommunity.dev/api/v1/posts/harmonyos-arkts-coding-rules-for-components-state-and-layout-fzq3/export/mdc" -o .cursor/rules/harmonyos-arkts-coding-rules-for-components-state-and-layout.mdcThen open a new session; Cursor picks it up from .cursor/rules/.
Manual install
Save harmonyos-arkts-coding-rules-for-components-state-and-layout.mdc as .cursor/rules/harmonyos-arkts-coding-rules-for-components-state-and-layout.mdc for this project or ~/.cursor/rules/harmonyos-arkts-coding-rules-for-components-state-and-layout.mdc for every project, then start a new session.
Rule
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
@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.
No result recorded yet. Added it? File a Tried-it report so the next person knows how it went in your editor.
Tried it
Reports from people who added this rule to their editor. They roll up into the badges above.
No one has filed a report yet. Try the prompt and be the first.
Related rules
- Generate AI-first design handoff notes for implementation agents
Produces a structured, machine-parseable design handoff document with exact values, states, breakpoints, and edge cases so AI coding agents can implement a design without guessing.
Coding · @gokbeyinac
- Generate realistic mock data, seeds, and fixtures as a TODO plan
A system-style role prompt that makes the model act as a test data engineer producing seeded, referentially consistent mock data (SQL, JSON, CSV, TypeScript) and API mock responses, with output written to TODO_mock-data.md as trackable checklists.
Coding · @wkaandemir
- Cursor rules enforcing clean, readable, maintainable code practices
A Cursor .mdc rule file that guides the assistant toward clean code: named constants, meaningful names, sparing comments, single-purpose functions, DRY, language style standards, extracted conditionals, continuous refactoring, and version control.
Coding · @patrickjs
- Semiotic chart-building assistant rules for AI coding tools
Cursor rules guiding an AI assistant to build data visualizations with the Semiotic React library, covering chart choice, props, push API, geo, realtime, and common pitfalls.
Coding · @patrickjs
- Security guardrails that keep an AI email assistant from being hijacked by malicious messages
A full system prompt giving an AI assistant that reads or manages email a security mindset: treat email as untrusted data, require approval for outward actions, avoid leaking private data, and report phishing and injection attempts calmly.
Productivity · @thanos0000
License: CC0v1 · published Nov 29, 2026
Comments
No comments yet. If you tried this prompt, say how it went.