docs(rules): fix contradictions, update technical rules, enforce rule structure
CI / CI configuration security checks (pull_request) Successful in 2s
CI / Capabilities and shell quality (pull_request) Successful in 15s
CI / Python tests and compilation (pull_request) Successful in 36s
CI / QMD unit tests (pull_request) Successful in 7s
CI / Build and inspect generated packages (pull_request) Successful in 16s
CI / Bash integration and installation guards (pull_request) Failing after 51s
CI / PowerShell tests on Ubuntu (pull_request) Failing after 1m45s
CI / Installed client configuration smoke tests (pull_request) Canceled after 1m24s
CI / CI configuration security checks (pull_request) Successful in 2s
CI / Capabilities and shell quality (pull_request) Successful in 15s
CI / Python tests and compilation (pull_request) Successful in 36s
CI / QMD unit tests (pull_request) Successful in 7s
CI / Build and inspect generated packages (pull_request) Successful in 16s
CI / Bash integration and installation guards (pull_request) Failing after 51s
CI / PowerShell tests on Ubuntu (pull_request) Failing after 1m45s
CI / Installed client configuration smoke tests (pull_request) Canceled after 1m24s
- Resolve contradictions: authorization is never a skipped "boundary check"; one browser token policy (BFF/HttpOnly cookies first, RFC 10017); one sanitizer-bypass rule; Angular responses are unknown until validated. - Add security rules for AI/LLM integration and Java XXE, concrete crypto and password-hashing parameters, and RFC 8725 JWT validation. - Update version-dependent guidance after checking official sources: Angular 22, TypeScript 6/7, Node 24+, .NET 10/C# 14, JDK 21-25, Spring Boot 4; add a Spring Boot and Spring Security topic. - Give every rule a unique level-1 title and scope line, keep language security files to language specifics, and fix routing for inbound vs outbound HTTP, XML parsing, and WPF/Angular parent rules. - Validate rule structure and routing in validate-config.py, with tests. - Fix CI issues found by a local run: shellcheck directive order, pinned ruff rule set, Invoke-Python test mock, CRLF-tolerant package checks, Windows-only credential test, and refreshed prompt-budget baselines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
79694fbaa2
commit
6159c6373c
62 files changed
+453
-300
No files matched your search
@@ -1,13 +1,18 @@
|
||||
# Angular Components, Change Detection, and Signals
|
||||
|
||||
Apply these rules when creating or changing Angular components, directives, signal state, change detection, or DOM access.
|
||||
|
||||
## Components
|
||||
|
||||
* Prefer standalone components, directives, and pipes for new work. Avoid introducing `NgModule` unless the existing architecture requires it.
|
||||
* Keep components small; move substantial business logic to a focused service or domain layer.
|
||||
* Keep dependencies explicit and follow the feature architecture. Avoid god components, god services, unnecessary wrappers, and abstractions without a concrete need.
|
||||
* Use `ChangeDetectionStrategy.OnPush` unless there is a concrete reason not to.
|
||||
* Use `ChangeDetectionStrategy.OnPush` unless there is a concrete reason not to, in both zone.js and zoneless applications.
|
||||
* Keep component state minimal and prefer immutable state updates.
|
||||
* Avoid direct mutation of shared state.
|
||||
* Keep inputs and outputs strongly typed.
|
||||
* Prefer signal-based inputs and outputs when consistent with the project.
|
||||
* In new code on Angular 19+, use `input()` and `input.required()`, `output()` (an `OutputEmitterRef`, not a signal), `model()` for intended two-way bindings, and signal queries (`viewChild`, `viewChildren`, `contentChild`, `contentChildren`). Keep `@Input`, `@Output`, and decorator queries only where the surrounding code uses them.
|
||||
* Use the `host` object in component metadata instead of `@HostBinding` and `@HostListener` in new code.
|
||||
* Avoid unnecessary two-way binding.
|
||||
* Avoid unnecessary component-to-component coupling.
|
||||
* Prefer explicit data flow from parent to child and explicit events upward.
|
||||
@@ -15,6 +20,12 @@
|
||||
* Use lifecycle hooks only when required.
|
||||
* Avoid complex initialization logic inside constructors.
|
||||
|
||||
## Change Detection
|
||||
|
||||
* Check whether the application uses zone.js or is zoneless: new applications are zoneless by default since Angular 21 (`provideZonelessChangeDetection`, stable since 20.2). Do not migrate between the two as a side effect of another task.
|
||||
* In zoneless applications, change template-bound state only through signals, `markForCheck`, the `async` pipe, or template event handlers. Mutating plain fields in `setTimeout` or promise callbacks does not update the view.
|
||||
* Do not add `NgZone` APIs (`onStable`, `onMicrotaskEmpty`, `runOutsideAngular`) for rendering logic; use `afterNextRender` or `afterRenderEffect` for DOM work after rendering.
|
||||
|
||||
## Signals and State
|
||||
|
||||
* Prefer signals for local and synchronous reactive state.
|
||||
@@ -22,5 +33,16 @@
|
||||
* Keep signals private when external mutation is not intended, and expose readonly state where practical.
|
||||
* Avoid circular signal dependencies.
|
||||
* Use `effect` only for actual side effects, not as a replacement for normal data flow. Keep effects small and deterministic, and clean up resources they create.
|
||||
* Use `linkedSignal` (Angular 20+) for writable state that resets when a source changes, instead of an `effect` that writes signals.
|
||||
* For parameter-driven reads, use `httpResource`, `resource`, or `rxResource` (stable since Angular 22; experimental in 19 to 21, so use them there only if the project already does). Use RxJS for event streams, cancellation semantics, and multi-step flows; convert with `toSignal` at the component edge, in an injection context. Never perform writes or mutations through resources.
|
||||
* Do not use global state unless multiple unrelated parts of the application genuinely need it.
|
||||
* Do not introduce a state-management library without a clear requirement.
|
||||
|
||||
## DOM and Browser APIs
|
||||
|
||||
* Prefer Angular APIs and declarative templates over direct DOM manipulation.
|
||||
* Use `Renderer2` only when direct rendering abstraction is actually needed.
|
||||
* Avoid accessing globals directly when it harms testability or SSR compatibility.
|
||||
* When the application uses SSR, guard `window`, `document`, `localStorage`, and similar browser-only APIs with `isPlatformBrowser`, or run DOM access in `afterNextRender` or `afterRenderEffect`, which run only in the browser.
|
||||
* Clean up event listeners, observers and timers.
|
||||
* Avoid layout thrashing in performance-sensitive code.
|
||||
@@ -1,11 +1,13 @@
|
||||
# Angular Forms and Routing
|
||||
|
||||
Apply these rules when building Angular forms, validation, routes, guards, or resolvers.
|
||||
|
||||
## Forms
|
||||
|
||||
* Prefer reactive forms for non-trivial forms.
|
||||
* Keep forms strongly typed.
|
||||
* Avoid untyped forms.
|
||||
* Follow the form approach the project uses. For non-trivial forms, use typed reactive forms (`FormGroup`, `FormControl`, `NonNullableFormBuilder`; `nonNullable` controls where reset should restore the initial value) and never `Untyped*` classes in new code.
|
||||
* Signal forms (`@angular/forms/signals`) are stable since Angular 22. Use them for new forms only when the project is on 22+ and has adopted them; do not migrate existing forms unasked.
|
||||
* Keep validation rules centralized and reusable where practical.
|
||||
* Validate on both client and server where required.
|
||||
* Never treat client-side validation as a security boundary.
|
||||
* Client-side validation is user experience; the server must validate every submission. Never treat client-side validation as a security boundary.
|
||||
* Keep form state separate from domain state when useful.
|
||||
* Avoid large components that combine layout, validation, persistence and business logic.
|
||||
* Display validation errors consistently.
|
||||
@@ -14,11 +16,13 @@
|
||||
## Routing
|
||||
|
||||
* Keep route definitions explicit and predictable.
|
||||
* Prefer lazy loading for larger feature areas.
|
||||
* Prefer lazy loading for larger feature areas with `loadComponent` or `loadChildren` pointing to standalone route arrays.
|
||||
* Write new guards and resolvers as functions (`CanActivateFn`, `ResolveFn`); keep class-based guards where the project uses them, since they remain supported.
|
||||
* Use `withComponentInputBinding()` to bind route parameters to component inputs where the project enables it.
|
||||
* Avoid loading large feature bundles eagerly without need.
|
||||
* Use route guards only for navigation behavior, not as a security boundary.
|
||||
* Authorization must still be enforced on the backend.
|
||||
* Keep resolvers focused.
|
||||
* Avoid expensive work during navigation unless required.
|
||||
* Keep route parameters strongly typed at application boundaries where practical.
|
||||
* Route and query parameters arrive as `string | null`. Parse and validate them before use and treat them as untrusted input.
|
||||
* Do not rely on client-side routing state for sensitive authorization decisions.
|
||||
@@ -1,33 +1,15 @@
|
||||
# Angular Performance
|
||||
|
||||
Apply these rules when optimizing Angular rendering, loading, bundle size, or hydration.
|
||||
|
||||
## Performance
|
||||
|
||||
* Use `OnPush`.
|
||||
* Use stable tracking in loops.
|
||||
* Avoid unnecessary change detection triggers.
|
||||
* Avoid repeated expensive template calculations.
|
||||
* Avoid unnecessary subscriptions.
|
||||
* Avoid unnecessary DOM rendering.
|
||||
* Lazy-load large features and heavy dependencies where appropriate.
|
||||
* Avoid large initial bundles.
|
||||
* Avoid importing full libraries when only a small part is required.
|
||||
* Avoid unnecessary deep cloning.
|
||||
* Avoid unnecessary object and array recreation in hot paths.
|
||||
* Keep state updates targeted.
|
||||
* Avoid unnecessary global state updates.
|
||||
* Measure bundle size and runtime performance before micro-optimizing.
|
||||
* Prefer architectural improvements over template-level micro-optimizations.
|
||||
Apply the TypeScript performance rule for general measurement, allocation, and bundle guidance, and these Angular-specific levers on top. Measure before optimizing.
|
||||
|
||||
## Performance Priority
|
||||
|
||||
Prioritize Angular performance work in this order:
|
||||
|
||||
* Application architecture
|
||||
* Network and API behavior
|
||||
* Bundle size and lazy loading
|
||||
* State architecture
|
||||
* Change detection
|
||||
* Rendering and DOM complexity
|
||||
* RxJS and subscription behavior
|
||||
* Memory allocations
|
||||
* CPU micro-optimizations
|
||||
|
||||
Never optimize based purely on assumptions.
|
||||
* Use `OnPush` and signals so change detection touches only what changed (see the components rule for zoneless applications).
|
||||
* Defer heavy, below-the-fold, or rarely used template parts with `@defer` and an explicit trigger such as `on viewport` or `on interaction`, with a placeholder that reserves layout space.
|
||||
* Use `NgOptimizedImage` (`ngSrc`) for images, with explicit dimensions and `priority` for the largest contentful image.
|
||||
* Lazy-load routes and heavy dependencies, and keep the bundle budgets in `angular.json` enforced; do not raise a budget to make a build pass without approval.
|
||||
* For server-side rendering, use `provideClientHydration()`, which includes incremental hydration since Angular 22; do not add the deprecated `withIncrementalHydration()` there. Use event replay instead of re-rendering on hydration.
|
||||
* Use `runOutsideAngular` only in zone.js applications, for high-frequency events that must not trigger change detection.
|
||||
* Keep RxJS and signal updates targeted; avoid global state updates for local changes.
|
||||
@@ -1,3 +1,7 @@
|
||||
# Angular RxJS
|
||||
|
||||
Apply these rules when writing or changing RxJS streams, subscriptions, or signal and observable interop in Angular.
|
||||
|
||||
## RxJS
|
||||
|
||||
* Use RxJS for asynchronous streams, events and complex reactive flows.
|
||||
|
||||
@@ -1,37 +1,20 @@
|
||||
# Angular Security and Accessibility
|
||||
|
||||
Apply these rules when Angular code renders untrusted content, binds HTML or URLs, configures HTTP security, handles tokens, or builds interactive UI. Load `rules-security-web` for the general browser rules and `rules-ui-ux-visual-and-accessibility` for general accessibility; this file adds only Angular specifics.
|
||||
|
||||
## Security
|
||||
|
||||
* Treat all external data as untrusted.
|
||||
* Never bypass Angular sanitization without a verified reason.
|
||||
* Avoid direct DOM manipulation.
|
||||
* Avoid `innerHTML` with untrusted content.
|
||||
* Avoid `bypassSecurityTrust*` unless explicitly required and the input is fully controlled.
|
||||
* Never expose secrets in frontend code.
|
||||
* Never store sensitive credentials in the Angular application.
|
||||
* Do not rely on frontend checks for authorization.
|
||||
* Enforce authentication and authorization on the backend.
|
||||
* Avoid leaking sensitive information through logs or error messages.
|
||||
* Use secure cookie or token handling according to the application's authentication architecture.
|
||||
* Avoid storing sensitive tokens in insecure browser storage without a deliberate security decision.
|
||||
* Do not disable security controls for convenience.
|
||||
|
||||
## DOM and Browser APIs
|
||||
|
||||
* Prefer Angular APIs and declarative templates over direct DOM manipulation.
|
||||
* Use `Renderer2` only when direct rendering abstraction is actually needed.
|
||||
* Avoid accessing globals directly when it harms testability or SSR compatibility.
|
||||
* Consider SSR and hydration compatibility for browser-specific code.
|
||||
* Guard access to `window`, `document`, `localStorage` and similar browser-only APIs when SSR is supported.
|
||||
* Clean up event listeners, observers and timers.
|
||||
* Avoid layout thrashing in performance-sensitive code.
|
||||
* Use `bypassSecurityTrust*` only as the shared web security rule allows: compile-time constants, developer-controlled values, or output of a maintained sanitizer, with the reason in a comment.
|
||||
* `[innerHTML]` is sanitized, but `ElementRef.nativeElement.innerHTML` and `Renderer2.setProperty(el, 'innerHTML', ...)` bypass sanitization; never use them with untrusted content.
|
||||
* Never build templates from user data or compile templates at runtime.
|
||||
* Angular's `HttpClient` sends the XSRF token (configured with `withXsrfConfiguration`) only on mutating requests to relative or same-origin URLs. APIs on another origin that use cookie authentication need their own CSRF protection.
|
||||
* Prefer `autoCsp` (build option, inline scripts only, not with SSR) or a nonce through `ngCspNonce` or `CSP_NONCE` over relaxing the Content Security Policy.
|
||||
* Never place server secrets in the Angular application. Handle session tokens as the shared web security rule defines: prefer `HttpOnly` cookies or a backend-for-frontend; tokens the app must hold stay in memory, and refresh tokens never go into `localStorage` or `sessionStorage`.
|
||||
* Route guards and hidden UI are navigation aids, not authorization; enforce authorization on the backend.
|
||||
|
||||
## Accessibility
|
||||
|
||||
* Use semantic HTML.
|
||||
* Preserve keyboard navigation.
|
||||
* Ensure interactive elements are actually interactive elements.
|
||||
* Do not replace buttons with clickable `div` elements.
|
||||
* Provide labels for form controls.
|
||||
* Maintain visible focus behavior.
|
||||
* Use ARIA only when native HTML semantics are insufficient.
|
||||
* Avoid unnecessary custom widgets.
|
||||
* Keep accessible names and states synchronized with UI state.
|
||||
* Bind ARIA attributes with `[attr.aria-*]`, and keep accessible names and states synchronized with signal or component state.
|
||||
* Use Angular CDK accessibility utilities (`FocusTrap`, `LiveAnnouncer`, `FocusMonitor`) instead of hand-written focus management, or `@angular/aria` where the project uses it.
|
||||
* After router navigation, move focus to the main content or heading and update the page title (`Title` service or route `title`).
|
||||
* Do not replace buttons or links with clickable `div` elements.
|
||||
@@ -1,9 +1,13 @@
|
||||
# Angular Dependency Injection, Services, and HTTP
|
||||
|
||||
Apply these rules when creating Angular services, configuring dependency injection, or calling HTTP APIs.
|
||||
|
||||
## Dependency Injection
|
||||
|
||||
* Prefer Angular dependency injection for application services.
|
||||
* Keep injected dependencies minimal.
|
||||
* Avoid service locator patterns.
|
||||
* Prefer `inject()` where it improves readability and is consistent with the project.
|
||||
* Prefer the `inject()` function over constructor parameter injection, as the Angular style guide recommends since v20; keep constructor injection where the surrounding code consistently uses it.
|
||||
* Do not inject services that are not used.
|
||||
* Scope services intentionally.
|
||||
* Prefer application-wide singletons only for truly shared stateless or coordinated state.
|
||||
@@ -27,13 +31,13 @@
|
||||
|
||||
* Keep API access centralized and strongly typed.
|
||||
* Prefer dedicated API clients or data-access services.
|
||||
* Do not use `any` for API responses.
|
||||
* Treat all server responses as untrusted at runtime.
|
||||
* Validate external data when the contract is security- or correctness-critical.
|
||||
* Do not use `any` for API responses. The type parameter of `HttpClient.get<T>()` or `httpResource<T>()` is a compile-time assertion, not validation.
|
||||
* Treat all server responses as `unknown` until validated, as in the TypeScript runtime-safety rule. Validate them with a schema or parser at the data-access boundary before they drive authorization, persistence, navigation, or rendering.
|
||||
* Keep DTOs separate from domain models when their responsibilities differ.
|
||||
* Avoid duplicate API calls.
|
||||
* Cache only when the invalidation strategy is clear.
|
||||
* Avoid manual URL string construction when typed helpers or centralized endpoints are available.
|
||||
* Configure HTTP with `provideHttpClient(withInterceptors([...]), withFetch())` and functional interceptors in new code, not `HttpClientModule` or `HTTP_INTERCEPTORS` classes.
|
||||
* Use interceptors only for cross-cutting concerns.
|
||||
* Do not put unrelated business logic into HTTP interceptors.
|
||||
* Handle cancellation where appropriate.
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
# Angular Templates and Styling
|
||||
|
||||
Apply these rules when writing Angular templates, control flow, or component styles.
|
||||
|
||||
## Templates
|
||||
|
||||
* Keep expressions short and readable.
|
||||
* Do not execute expensive methods from templates.
|
||||
* Avoid function calls in templates when their result can be derived or cached.
|
||||
* Reading signals and `computed` values in templates is correct. Do not call other methods that compute or allocate from templates; use `computed` or a pure pipe instead.
|
||||
* Avoid complex conditions directly in markup.
|
||||
* Prefer derived state in TypeScript over repeated template expressions.
|
||||
* Use Angular control flow syntax such as `@if`, `@for` and `@switch` for new code.
|
||||
* Always provide stable tracking for repeated collections.
|
||||
* In `@for`, track a stable unique key such as `track item.id`; use `$index` only for static lists that never reorder. For legacy `*ngFor`, supply `trackBy`.
|
||||
* Avoid deeply nested template structures.
|
||||
* Split large templates into focused components when it improves maintainability.
|
||||
* Avoid unnecessary DOM elements.
|
||||
* Use semantic HTML.
|
||||
* Prefer native HTML behavior before custom implementations.
|
||||
* Keep accessibility in mind when choosing elements and interactions.
|
||||
* Use semantic HTML and native elements before custom implementations; see the accessibility section of the Angular security and accessibility rule.
|
||||
|
||||
## Styling
|
||||
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
# Angular Testing and Architecture
|
||||
|
||||
Apply these rules when writing Angular tests, organizing features, or changing Angular package versions.
|
||||
|
||||
## Testing
|
||||
|
||||
Apply the TypeScript testing rule for general test design, and these Angular specifics.
|
||||
|
||||
* Use the project's test runner. New CLI projects use Vitest since Angular 21; Karma remains supported, so do not migrate runners as part of another task.
|
||||
* In zoneless tests, configure `TestBed` with `provideZonelessChangeDetection()` and use `await fixture.whenStable()` instead of `fakeAsync` and `tick`, which require zone.js.
|
||||
* Set signal inputs with `fixture.componentRef.setInput()`. Test HTTP with `provideHttpClient()` plus `provideHttpClientTesting()` and `HttpTestingController`. Prefer Angular CDK component harnesses for interacting with material or CDK components.
|
||||
* Test behavior, not implementation details.
|
||||
* Prefer focused component tests.
|
||||
* Test critical user interactions.
|
||||
@@ -26,29 +35,10 @@
|
||||
* Avoid exposing internal implementation details across feature boundaries.
|
||||
* Prefer local ownership of state and logic.
|
||||
|
||||
## Code Quality
|
||||
## Code Quality and Dependencies
|
||||
|
||||
* Use strict TypeScript settings.
|
||||
* Avoid `any`.
|
||||
* Avoid unnecessary type assertions.
|
||||
* Avoid non-null assertions unless safety is guaranteed.
|
||||
* Prefer modern, readable syntax.
|
||||
* Use descriptive names.
|
||||
* Avoid vague names such as `data`, `item`, `value` or `temp` when better names exist.
|
||||
* Remove dead code.
|
||||
* Remove unused imports and dependencies.
|
||||
* Add comments only for non-obvious decisions or public contracts.
|
||||
* Treat Angular, TypeScript and lint warnings seriously.
|
||||
* Do not suppress diagnostics without a concrete reason.
|
||||
* Prefer correctness, security and maintainability over cleverness.
|
||||
|
||||
## Dependency Rules
|
||||
Apply the TypeScript rules for types, style, and dependency review, plus these Angular specifics.
|
||||
|
||||
* Treat Angular compiler, template type-checking, and lint warnings seriously; do not suppress them without a concrete reason.
|
||||
* Keep all `@angular/*` packages on the same major and minor version, and upgrade them with `ng update` so migrations run.
|
||||
* Prefer Angular and browser platform capabilities before adding third-party libraries.
|
||||
* Do not add dependencies without a clear benefit.
|
||||
* Avoid libraries that duplicate existing framework functionality.
|
||||
* Avoid abandoned or poorly maintained packages.
|
||||
* Keep Angular package versions aligned.
|
||||
* Do not mix incompatible Angular package versions.
|
||||
* Respect the existing lockfile and package manager.
|
||||
* Avoid unrelated dependency upgrades.
|
||||
Reference in new issue
Block a user