component-structure

Enforces Angular component file conventions for selectors, templates, and qa-dataid anchors.

1|Updated Jan 14, 2024
One-click install
npx skills add https://github.com/Eyhenij/rt-tools --skill component-structure-eyhenij
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: component-structure
Source: https://github.com/Eyhenij/rt-tools/tree/main/.claude/skills/component-structure
Command: npx skills add https://github.com/Eyhenij/rt-tools --skill component-structure-eyhenij

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Angular component files drift in structure across a codebase: decorator property order, import grouping, template method calls, and missing test anchors all diverge without a written rule. This Skill defines how a component file and its template must be arranged so every component in the tree follows the same conventions. ## Core Features & Use Cases - Component file conventions: Mandates element selectors with a tree prefix, block classes on the host via host: { class: ... }, and computed values instead of template method calls. - Test anchor rules: Requires the qa-dataid attribute on every interactive element as the stable anchor for specs, separate from accessibility attributes. - Safe rendering of external content: Directs parsing of outside text into a node tree with a closed markup list and scheme-checked links instead of string interpolation. - Use Case: When editing any *.component.ts and its template, load this rule to check selector shape, host class placement, conditional binding pitfalls, and anchor coverage before committing. ## Quick Start Load the component-structure rule and review my edited component file against its conventions for selectors, host classes, computed values, and qa-dataid anchors.

Frequently Asked Questions about component-structure

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure an Angular component file correctly?

Use an element selector with the tree prefix, place the BEM block class on the host via host metadata, and compute template values with computed() instead of calling methods. Every interactive element carries a qa-dataid anchor in kebab-case.

Why should Angular templates not call methods?

Template method calls like {{ getTotal() }} re-run on every change detection cycle and are banned by the linter rule. Values the template needs are computed in the class with computed() or delivered through a pure pipe.

What is qa-dataid used for in component testing?

qa-dataid is a kebab-case attribute placed on every interactive element as the sole anchor for specs. BEM classes change with layout and role-or-text queries break across translation locales, so the anchor stays stable.

Can an Angular component use an attribute selector?

No. Components are allowed only element selectors with the tree prefix and a hyphenated name; directives use attribute selectors with one-word names. A technique needing a foreign tag is written as a directive from the start.

Why does href="#id" fragment navigation fail in Angular builds?

The build uses <base href="/">, so the browser resolves the fragment against the base and triggers a full navigation with reload instead of scrolling. Use the router instead: <a [routerLink]="[]" fragment="booking">.

How should externally sourced text be rendered in a component?

Parse the text with a pure function into a node tree and let the component draw the nodes. The markup list is closed, unknown content stays visible as characters, and links are allowed only for known safe schemes.