code-style

A set of coding standards for TypeScript and React projects connected to Sitecore XM Cloud, a cloud content-management platform. It covers code organization, naming, types, functions, and side effects.

In plain words
What is it for?
Use it when writing or reviewing TypeScript, React components, Sitecore data integrations, and other code in an XM Cloud starter project.
Why use it?
It gives contributors shared expectations for readable, modular code and helps avoid inconsistent patterns. It also encourages safer handling of data and application state.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/sitecore/xmcloud-starter-js/code-style
Clone the repo
git clone --depth 1 https://github.com/Sitecore/xmcloud-starter-js

Made for: Cursor.

Per session 1,312 This file is loaded in full into every session.
When invoked 1,312 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01312 $0.01312
Opus 5 $0.00656 $0.00656
Sonnet 5 $0.00262 $0.00262
Haiku 4.5 $0.00131 $0.00131

Measured 2d ago against content hash b37805bc022e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

code-style scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/code-style.mdc · 204 lines

How it starts

The opening of the file, as written. The whole thing — 204 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Code Style

Vibe-Coding Principles

Core Philosophy:

  • Write clean, modular, and idiomatic code
  • Prefer declarative over imperative patterns
  • Make code readable and self-documenting
  • TypeScript-first development approach
  • Component-driven architecture with XM Cloud integration

Code Organization:

  • Use modern JavaScript/TypeScript features
  • Export public types at module boundaries
  • Prefer pure functions and thin wrappers
  • No top-level side effects (except page entry points)
  • Modular architecture with clear separation of concerns

Code Quality Standards

TypeScript Usage:

  • Enable strict mode in all projects
  • Prefer explicit types over any
  • Use discriminated unions for complex state
  • Export types at module boundaries for reusability
  • Define proper interfaces for XM Cloud data structures

Functional Programming:

  • Prefer pure functions where possible
  • Use immutable data patterns
  • Avoid side effects in business logic
  • Compose small, focused functions
  • Use React hooks appropriately

Readability:

  • Use descriptive variable and function names
  • Keep functions small and focused (single responsibility)
  • Prefer self-documenting code over extensive comments
  • Use consistent naming patterns across all starters

Component Development

React Best Practices:

  • Use functional components with hooks
  • Implement proper prop validation with TypeScript
  • Handle loading and error states explicitly
  • Use React.memo for performance optimization when needed
  • Follow React 18+ patterns and concurrent features

XM Cloud Component Patterns:

  • Always validate field existence before rendering
  • Provide meaningful fallbacks for missing content
  • Use Sitecore field components for proper rendering
  • Handle both editing and preview modes
  • Implement proper error boundaries
  • Handle destructuring, undefined errors and null values in datasource and field values gracefully
// Good component pattern
import { Text, Image, useSitecore } from '@sitecore-content-sdk/nextjs';

interface HeroProps {
  fields: {
    data?: {
      datasource?: {
        title?: { jsonValue?: Field };
        subtitle?: { jsonValue?: Field };
        backgroundImage?: { jsonValue?: Field };
      };
    };
  };
}

export default function Hero({ fields }: HeroProps) {
  const { page } = useSitecore();
  const { isEditing } = page.mode;

  if (!fields) {
    return <div>Hero content not configured</div>;
  }

  // Handle destructuring errors with safe fallbacks
  const { data } = fields || {};
  const { datasource } = data || {};
  const { title, subtitle, backgroundImage } = datasource || {};

  return (
    <section className="hero">
      {/* Show field components in editing mode even if no content */}
      {(title?.jsonValue?.value || isEditing) && <Text field={title?.jsonValue} tag="h1" />}
      {(subtitle?.jsonValue?.value || isEditing) && <Text field={subtitle?.jsonValue} tag="p" />}
      {(backgroundImage?.jsonValue?.value?.src || isEditing) && (
        <Image field={backgroundImage?.jsonValue} />
      )}
    </section>
  );
}

Read the full file on GitHub · 204 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 204 lines · 1,312 tokens per session scan A b37805bc022e

Subscribe to this mod's changes

code-style is a cursor rule published in the GitHub repository Sitecore/xmcloud-starter-js (29 stars, last pushed 7d ago), licensed Apache-2.0. It adds 1,312 tokens to every session, about $0.0066 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.