Rules

Review the governance rules and stable FUI codes shipped by Fragments.

All rules

A rule decides whether a given usage fact is a violation; it does not care which surface asked. This reference is generated from the core registries and currently covers 25 rules across 9 domains. The Fragments-only tokens/require-dual-fallback convention is available through the full fragments preset but is excluded from customer defaults.

Components

Components governance rules
Rule
FUI code
Tier
Title
components/unknown-propFUI6005Opt-inComponent prop is unknown
components/forbidden-prop-valueFUI6004Opt-inProp value is forbidden
components/preferred-componentFUI1002Opt-inPreferred component should be used
components/prefer-libraryFUI1004ContractLibrary component should be preferred
components/shadow-componentFUI1007ContractComponent shadows a canonical primitive

Props

Props governance rules
Rule
FUI code
Tier
Title
props/invalid-valueFUI6002Opt-inProp value is invalid

Imports

Imports governance rules
Rule
FUI code
Tier
Title
imports/preferred-pathFUI1003Opt-inImport should use the preferred path

Styles

Styles governance rules
Rule
FUI code
Tier
Title
styles/no-raw-colorFUI2005Opt-inRaw color should use a token
styles/no-raw-dimensionsFUI2004Opt-inRaw dimension should use a token
styles/no-raw-spacingFUI2006Opt-inRaw spacing should use the scale
styles/no-raw-typographyFUI2016Opt-inRaw typography should use a token

Tailwind

Tailwind governance rules
Rule
FUI code
Tier
Title
tailwind/arbitrary-colorFUI2007Opt-inTailwind arbitrary color should use a token
tailwind/arbitrary-spacingFUI2008Opt-inTailwind arbitrary spacing should use the scale
tailwind/forbidden-paletteFUI2009Opt-inTailwind palette is forbidden
tailwind/off-scale-spacing-tokenFUI2011Opt-inTailwind spacing token is off scale
tailwind/raw-color-via-tokenFUI2010Opt-inTailwind color should use a resolved token
tailwind/unknown-classFUI2012Opt-inTailwind class is unknown

Tokens

Tokens governance rules
Rule
FUI code
Tier
Title
tokens/require-dual-fallbackFUI2003Opt-inToken fallback is required
tokens/css-vars-must-be-definedFUI2015ContractCSS variable is not in the contract vocabulary
tokens/upstream-driftFUI2017ContractLocal token differs from its declared upstream source

Theme

Theme governance rules
Rule
FUI code
Tier
Title
theme/no-theme-coupled-literalFUI2014Opt-inTheme-coupled literal should use a semantic token

Accessibility

Accessibility governance rules
Rule
FUI code
Tier
Title
a11y/required-accessible-nameFUI3001Opt-inAccessible name is required
a11y/standardFUI3002Opt-inAccessibility standard failed

Composition

Composition governance rules
Rule
FUI code
Tier
Title
composition/cardinalityFUI5003Opt-inToo many of a component in one region
composition/co-occurrenceFUI5004Opt-inRequired companion component is missing from the region

Composition rules

Experimental

Composition rules govern how components are arranged inside a container — not just whether a single node is valid, but whether a region holds the right mix of children. A region is matched by its canonical container component — for example a ButtonGroup — and is local to one element tree, so the same pattern in two separate groups is two separate regions. Composition rules are off by default and self-activate when patterns are declared.

Composition is decided statically. A child counts only when its prop resolves to a literal value — a dynamic variant={kind} is unknown, never treated as a match and never treated as absent. Dynamic arrangements are out of scope for these rules.
  • composition/cardinality (FUI5003): Flags a selected component count above max or below min in one region. Example: two primary Buttons in a single ButtonGroup when max is 1.
  • composition/co-occurrence (FUI5004): Flags a selected component that is missing a companion the policy requires in the same region. Example: a primary Button in a ButtonGroup with no secondary Button.

The cardinality constraint supports max ("At most N …") and min ("At least N …"). Because only statically resolved members count, dynamic members do not count toward satisfying a minimum.

Authoring

Patterns are authored once and read by every surface. Define them as governance policy, where each pattern names a region, a child selector, and a constraint:

fragments.config.ts
export default {
  govern: {
    rules: {
      'composition/cardinality': {
        enabled: true,
        severity: 'warn',
        options: {
          patterns: [
            {
              region: { component: 'ButtonGroup' },
              select: { component: 'Button', prop: 'variant', value: 'primary' },
              constraint: { kind: 'cardinality', max: 1 },
            },
          ],
        },
      },
    },
  },
};

Components can also carry their own composition contract. The authoring block below lowers to the same patterns the rule reads, so the constraint travels with the component:

ButtonGroup.fragment.tsx
contract: {
  composition: [
    {
      inRegion: 'ButtonGroup',
      rule: { atMost: 1, of: { component: 'Button', prop: 'variant', value: 'primary' } },
    },
    {
      inRegion: 'ButtonGroup',
      rule: {
        when: { component: 'Button', prop: 'variant', value: 'primary' },
        require: { prop: 'variant', value: 'secondary' },
      },
    },
  ],
},

Composition findings flow through the shared engine, so they reach every governance surface without extra wiring — Fragments Cloud lists them under the Composition category with no per-rule registration.

Tailwind rules

Tailwind v4

The Tailwind scanner extracts literal class names from JSX, parses each class into a structured utility, resolves token-form classes through project @theme declarations and bundled Tailwind v4 defaults, then runs governance rules over the resulting facts. Tailwind rules are Tier B (opt-in), so they do not run in the customer default until you enable them.

The resolver is CSS-only. It does not import or execute tailwind.config.ts, plugins, or project JavaScript.

Enable

Start with the Tailwind preset for a project-level scale and an opinionated palette stance:

terminal
fragments check --preset tailwind --format summary

Configure palette policy in fragments.config.ts when you want explicit allow or deny patterns:

fragments.config.ts
import { defineConfig } from '@usefragments/core';

export default defineConfig({
  govern: {
    presets: ['tailwind@2'],
    tailwind: {
      palette: {
        allow: ['brand-*', 'neutral-*'],
        deny: ['red-*', 'green-*', 'blue-*'],
      },
    },
  },
});

Resolver rules

  • tailwind/forbidden-palette FUI2009: Flags resolved color tokens that match deny patterns or miss allow patterns. Example: bg-red-500 with deny: ["red-*"].
  • tailwind/off-scale-spacing-token FUI2011: Checks resolved spacing tokens against the project spacing scale after unit normalization. Example: p-3 resolving to 12px on a scale without 12.
  • tailwind/raw-color-via-token FUI2010: Flags Tailwind tokens outside the allowed palette when they resolve to raw color literals. Example: bg-red-500 resolving to #ef4444 when allow: ["brand-*"].

Arbitrary rules

  • tailwind/arbitrary-color FUI2007: Flags raw color literals in arbitrary-value classes such as bg-[#abc123].
  • tailwind/arbitrary-spacing FUI2008: Flags arbitrary margin, padding, gap, and space utilities that are not on scale.

Strict mode

The tailwind/unknown-class rule (FUI2012) is off by default. Enable it when CI should fail or warn on stale palette references and Tailwind typos:

fragments.config.ts
export default {
  govern: {
    rules: {
      'tailwind/unknown-class': { enabled: true, severity: 'info' },
    },
  },
};

Fragments Cloud accepts all Tailwind rule IDs, includes them in findings filters and governance rule settings, and stores class scan counters from the CLI report. Tailwind findings also carry resolver provenance such as theme-css or default in their structured attributes.

Next steps