clean
Correct code carrying no defects. Measures precision: the pass condition is zero comments, and a reviewer that flags anything here fails.
What this is
Correct code with nothing wrong in it. It measures precision, and its pass condition is the strict one: zero comments. A reviewer that flags everything scores perfect recall on every other corpus here and is useless — this is the half that catches that, and it is why the canary runs both together.
How to onboard it
Nothing is installed and nothing here is ever merged. The corpus is used by opening a throwaway pull request on a pilot repository already onboarded for this stack, adding this directory and seeded/clean together. Label it redline-exempt so the readiness gate does not block a pull request nobody will merge, wait for the automated review to finish, then score it.
seed-canary.yml does exactly this on a schedule and closes the pull request afterwards, including when the run fails.
How to use it
$ GH_TOKEN=... npx redlinegate metrics score-seeds --repo <org>/<repo> --pr <n>
Expected output
Zero review comments. Any comment on this corpus is a false positive and fails the canary run outright — there is no threshold to tune, because a reviewer allowed a few false positives on known-correct code cannot be trusted to be quiet on real code.
How to edit it
Add a defect by adding the code and one marker line above it. There is no separate expectations file to keep in sync — scripts/score-seeds.mjs parses the markers straight out of the source:
SEED <n> [BLOCKER|HIGH|SUGGESTION] (<stack>/<rule-slug>) <short description>scripts/validate.mjs fails CI if a seed cites a rule that does not exist, or claims a severity higher than that rule carries in the standard — so a marker cannot quietly drift away from the rule it is testing.
The full file
// Redline precision corpus. This file is deliberately CORRECT.
// Any review comment on it is a false positive. Zero findings is a pass.
//
// It is written to bait the common nitpick failures: unmemoised values, "missing" error
// handling on internal calls, direct index access, an effect that is genuinely necessary.
import { useCallback, useEffect, useRef, useState } from 'react';
import { useQuery } from '@tanstack/react-query';
type Plan = { id: string; label: string; priceMinor: number };
const formatter = new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'GBP' });
async function fetchPlans(signal: AbortSignal): Promise<Plan[]> {
const res = await fetch('/api/plans', { signal });
if (!res.ok) throw new Error(`plans: ${res.status}`);
return res.json();
}
export function PlanPicker({ onSelect }: { onSelect: (plan: Plan) => void }) {
const [selectedId, setSelectedId] = useState<string | null>(null);
const listRef = useRef<HTMLUListElement>(null);
const { data: plans, error } = useQuery({
queryKey: ['plans'],
queryFn: ({ signal }) => fetchPlans(signal),
});
// Derived during render, not synced through an effect.
const selected = plans?.find((plan) => plan.id === selectedId) ?? null;
// A real external-system effect: focus is not derivable from render output.
useEffect(() => {
if (!selected) return;
listRef.current?.focus();
}, [selected]);
const handleSelect = useCallback(
(plan: Plan) => {
setSelectedId(plan.id);
onSelect(plan);
},
[onSelect]
);
if (error) return <p role="alert">Plans are unavailable right now.</p>;
if (!plans) return <p>Loading plans…</p>;
return (
<ul ref={listRef} tabIndex={-1}>
{plans.map((plan) => (
<li key={plan.id}>
<button type="button" onClick={() => handleSelect(plan)}>
{plan.label} — {formatter.format(plan.priceMinor / 100)}
</button>
</li>
))}
{plans.length === 0 ? <li>No plans available.</li> : null}
</ul>
);
}
// Redline precision corpus. This file is deliberately CORRECT.
// Any review comment on it is a false positive. Zero findings is a pass.
package clean
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"time"
)
var errUpstream = errors.New("upstream unavailable")
type Client struct {
http *http.Client
base string
}
func NewClient(base string) *Client {
return &Client{
http: &http.Client{Timeout: 3 * time.Second},
base: base,
}
}
type Balance struct {
AccountID string `json:"accountId"`
Minor int64 `json:"minor"`
}
func (c *Client) Balance(ctx context.Context, accountID string) (Balance, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.base+"/balance/"+accountID, nil)
if err != nil {
return Balance{}, fmt.Errorf("build balance request: %w", err)
}
resp, err := c.http.Do(req)
if err != nil {
return Balance{}, fmt.Errorf("call balance: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return Balance{}, fmt.Errorf("balance status %d: %w", resp.StatusCode, errUpstream)
}
var balance Balance
if err := json.NewDecoder(resp.Body).Decode(&balance); err != nil {
return Balance{}, fmt.Errorf("decode balance: %w", err)
}
return balance, nil
}
// Handler is the HTTP boundary: it validates input and maps errors to statuses. The
// internal call above is trusted to return a typed error, so there is no second layer
// of defensive checking here.
func (c *Client) Handler(w http.ResponseWriter, r *http.Request) {
accountID := r.URL.Query().Get("accountId")
if accountID == "" {
http.Error(w, "accountId is required", http.StatusBadRequest)
return
}
balance, err := c.Balance(r.Context(), accountID)
if errors.Is(err, errUpstream) {
http.Error(w, "upstream unavailable", http.StatusBadGateway)
return
}
if err != nil {
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(balance); err != nil {
// The response is already partially written; there is nothing left to signal.
return
}
}