All files / packages/sds-customization-compliance/src/audit types.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143                                                                                                                                                                                                                                                                                             
/**
 * Audit-layer types.
 *
 * Kept separate from the top-level `src/types.ts` because nothing outside
 * `src/audit/` and `src/checks/` should need to reason about the raw diff
 * output — the rest of the package works with {@link ComplianceRow}s.
 */
 
/** A [ids, classes, types] specificity triple. */
export type Specificity = readonly [number, number, number];
 
/** A single declaration extracted from a component's flattened CSS. */
export interface DeclModel {
  prop: string;
  rawValue: string;
  /** Every `--slds-c-*` hook referenced in `rawValue`, in order of first appearance. */
  hooksRead: string[];
  /** Final literal/`transparent`/`var(--slds-g-*)` fallback in the `var()` chain, or `null`. */
  terminalFallback: string | null;
  /** Ordered list of `var()` token refs (outermost first). */
  varChain: string[];
  /**
   * 1-based line number where the declaration was authored. Captured from
   * the postcss source map when available; `null` when the declaration was
   * synthesized (no source position).
   */
  line: number | null;
  /**
   * Absolute path of the source file this declaration was authored in,
   * captured from postcss `decl.source.input.from`. After `@import`
   * flattening this points at the *importing* file — useful when the
   * containing FileModel was loaded via `flattenCss` and pulls in
   * sibling CSS. `null` when the source position was not available.
   */
  source: string | null;
}
 
/** Aggregate motion/kinetics signals for a single flattened file. */
export interface MotionSignals {
  reducedMotionBlocks: number;
  kxRules: number;
}
 
/**
 * One hook-prop assignment captured from a flattened CSS root: `--slds-c-x: …`.
 * Carries the raw value plus source-position info so downstream consumers
 * can cite file + line in reports. `source` is the absolute path of the
 * file the declaration was authored in; `line` is the 1-based line number.
 * Both are `null` when the source position was not available (e.g.
 * synthesized rules in tests).
 */
export interface HookAssignment {
  value: string;
  source: string | null;
  line: number | null;
}
 
/** Flattened-CSS model for a single file. */
export interface FileModel {
  source: string;
  declsBySelector: Map<string, DeclModel[]>;
  /**
   * Hook *prop* assignments keyed by selector — declarations whose property is
   * a `--slds-c-*` custom property. Populated for every file (always present,
   * may be empty) so downstream consumers can project a themeData-style view
   * directly off the in-memory model without reparsing CSS. Legacy files
   * rarely assign hook props; base.css often does in state/composition scopes.
   */
  assignmentsBySelector: Record<string, Record<string, HookAssignment>>;
  motion: MotionSignals;
}
 
/** Legacy `<name>.css` model (a component-tagged `FileModel`). */
export interface LegacyModel extends FileModel {
  name: string;
}
 
/** Per-theme hook assignments, `{ selector: { hookProp: HookAssignment } }`. */
export interface ThemeAssignmentsBlock {
  source: string;
  assignmentsBySelector: Record<string, Record<string, HookAssignment>>;
  motion: MotionSignals;
}
 
/** "Effective new" model = themes/base.css + per-theme hook assignments. */
export interface EffectiveNewModel {
  name: string;
  base: FileModel | null;
  themes: Record<string, ThemeAssignmentsBlock | null>;
}
 
/** Diff severity buckets. */
export type Severity = 'breaking' | 'warning' | 'info';
 
/** Severity counts used by compliance-row scoring. */
export interface FlagSummary {
  breaking: number;
  warning: number;
  info: number;
}
 
/**
 * "Side" of a flag. Every field is optional because different flag ids
 * populate different subsets — e.g. `hook-renamed` uses `{ hook }`,
 * `property-removed` uses `{ prop, rawValue, hooks }`.
 *
 * `source` + `line` cite where the offending declaration was authored,
 * threaded through from the audit's `DeclModel`. Both are optional
 * because some flag ids (`hook-renamed`, `kinetics-or-motion-removed`,
 * `audit-incomplete`) have no single authoring location to point at.
 */
export interface FlagSide {
  hook?: string;
  prop?: string;
  rawValue?: string;
  terminal?: string | null;
  hooks?: string[];
  selector?: string;
  themes?: string[];
  specificity?: Specificity;
  /** Path of the file the declaration was authored in (absolute, as recorded by postcss). */
  source?: string | null;
  /** 1-based line number where the declaration was authored. */
  line?: number | null;
}
 
/** A single diff result. Flag ids are stable strings — see diff.ts for the enum. */
export interface Flag {
  id: string;
  severity: Severity;
  selector?: string;
  legacy?: FlagSide | null;
  next?: FlagSide | null;
  detail?: string;
  needsReview?: boolean;
}
 
/** Shared context passed through per-selector diff helpers. */
export interface DiffContext {
  assignedByAny: Set<string>;
  assignedByAll: Set<string>;
}