# ServiceNow React Plugins Review Rules

> Auto-generated by pr-review-rules-generator skill on 2026-02-24
> Source: git history mining (DEF commits, reverts) + domain expertise interview

## Overview

Rules for the ServiceNow-specific react plugins (`src/servicenow/`), SWC transpiler integration
(`src/swc/`), and seismic component integration (`src/seismic/`). `src/servicenow/react-plugins.ts`
is the highest-churn file in the repo (23 changes), and the seismic integration has been reverted
twice.

## Rules

---

## Rule ID: node_env_specific_replace

**Summary:** Use precise `process.env.NODE_ENV` replacement — do not use broad process global polyfill for this

**Rationale:** DEF0784528 required two fixes: first, a switch from a broad `process` global polyfill
to a specific `process.env.NODE_ENV` string replacement; then a further refinement to use an
even more targeted replace pattern to enable dead code elimination during minification. Broad
process polyfills prevent bundlers from statically analyzing `process.env.NODE_ENV` references,
which means `if (process.env.NODE_ENV === 'production')` blocks are never tree-shaken in the
consumer's bundle. The replace must be specific enough to allow downstream bundlers to eliminate
dead branches.

**Scope:**
- Paths: `src/servicenow/**`, `src/swc/**`

**Detection Guidance:** Look for uses of `@rollup/plugin-replace` in the ServiceNow react plugin
setup. Verify the replace value is specifically targeting `process.env.NODE_ENV` (not `process`
broadly). Check that the replacement string is a JSON-encoded string literal (e.g.,
`JSON.stringify('production')`) rather than a variable reference, so downstream bundlers can
statically evaluate it. Flag any reversion to a `process` global polyfill for handling NODE_ENV.

**Severity:** `error`

**Source:**
- Type: `incident`
- Refs: DEF0784528, 3abf003, bc551dc
- Confidence: high

**Override:**
- Allowed: false
- Requires: n/a

**Examples:**

### Violation Example
```typescript
// ❌ Bad: broad process polyfill prevents dead code elimination
replace({
  'process': JSON.stringify({ env: { NODE_ENV: 'production' } })
})
```

### Correct Example
```typescript
// ✅ Good: specific replacement for the exact string that needs substituting
replace({
  'process.env.NODE_ENV': JSON.stringify('production'),
  preventAssignment: true
})
```


---

## Rule ID: seismic_integration_regression

**Summary:** Changes to the seismic plugin must be tested against the full seismic component build pipeline

**Rationale:** The seismic integration (`src/seismic/`) has been reverted twice (commits `0d33548`,
`f95c95e`, `4c81755`, `f5c74c5`) due to regressions introduced by seemingly small changes. The
seismic plugin interacts with CSS extraction, skip-vendor-prefix validation, and the ServiceNow
component build pipeline in non-obvious ways. Even changes that appear isolated often cause
downstream breakage. The plugin is currently in the main build and considered stable, which
means regressions have immediate impact.

**Scope:**
- Paths: `src/seismic/**`, `test/seismic/**`

**Detection Guidance:** For any change to the seismic plugin: (1) verify that existing tests in
`test/seismic/` still pass, (2) check whether the PR includes seismic-specific test coverage for
the changed behavior, (3) look for whether CSS extraction and `skipVendorPrefixValidation` options
are still respected, (4) check that the plugin's interaction with the `uxf-build` directory
convention is unchanged. If changes were only tested with a non-seismic build, flag this.

**Severity:** `warning`

**Source:**
- Type: mined
- Refs: 0d33548, f95c95e, 4c81755, f5c74c5
- Confidence: high

**Override:**
- Allowed: true
- Requires: justification


---

## Rule ID: swc_version_sync

**Summary:** `@swc/core` and `@swc/wasm-web` must always be pinned to the same exact version

**Rationale:** The SWC transpiler is used in both Node builds (`@swc/core`) and browser/WASM
builds (`@swc/wasm-web`). These two packages must always be on the same version — mismatches
cause inconsistent transpilation output between environments, which manifests as subtle runtime
differences that are hard to debug. The SWC parser config was also reverted (commit `c46f0a3`)
when TypeScript import attribute support was added prematurely, confirming that SWC config changes
carry real risk.

**Scope:**
- Paths: `package.json`, `src/swc/**`

**Detection Guidance:** When reviewing `package.json` changes, check that `@swc/core` and
`@swc/wasm-web` have identical version strings. Both must use exact pinning (no `^` or `~`
ranges). If only one is bumped, flag this as a required fix. For changes to `src/swc/module.ts`
or SWC parser config, check that the new config is supported by the pinned SWC version and
has been verified in both Node and browser build outputs.

**Severity:** `error`

**Source:**
- Type: mined
- Refs: bce3684, c46f0a3, interview
- Confidence: high

**Override:**
- Allowed: false
- Requires: n/a

**Examples:**

### Violation Example
```json
// ❌ Bad: versions are out of sync
{
  "@swc/core": "1.15.11",
  "@swc/wasm-web": "1.15.9"
}
```

### Correct Example
```json
// ✅ Good: exact same version, exact pinning
{
  "@swc/core": "1.15.11",
  "@swc/wasm-web": "1.15.11"
}
```


---

## Attribution

All rules are traceable to specific sources:
- `incident` = Direct from production defect (DEF*)
- `mined` = Derived from git history analysis (reverts, high-churn)
- `interview` = Captured during domain expertise interview

## Override Mechanism

To override a rule in a PR:

1. **In PR description:**
   ```markdown
   <!-- pr-review: skip seismic_integration_regression reason="Justification here" -->
   ```

2. **In repo config (`.pr-review-config.yaml`):**
   ```yaml
   overrides:
     - rule_id: seismic_integration_regression
       paths: ["test/seismic/**"]
       reason: "Test-only change, no production code modified"
   ```

Note: Rules marked `override.allowed: false` cannot be skipped without approval.
