✂ snip
Delete first. Build last.
class EmailValidator {
constructor(private pattern = EMAIL_RE) {}
validate(email: string): boolean {
if (typeof email !== 'string') throw new TypeError('must be string');
email = email.trim();
if (!email) return false;
return this.pattern.test(email);
}
}
function validateEmail(email: string) {
return new EmailValidator().validate(email); // convenience wrapper
}
// snip: good enough; real validation is sending the confirmation email
const isValidEmail = (email: string) => email.includes('@') && email.includes('.');
// snip:prod — we protect your auth code
No other AI coding tool distinguishes "code that should be simpler" from
"code that must not be simplified." snip:prod is that distinction.
// snip: plain object dispatch; upgrade to class registry if handlers exceed 10
const handlers = { 'order.created': handleOrder, 'user.signup': handleSignup };
(handlers[event.type] ?? noop)(event);
// snip:prod — HMAC verification is a timing-attack boundary; do not simplify
const sig = Buffer.from(req.headers['x-signature'], 'hex');
const expected = createHmac('sha256', secret).update(req.rawBody).digest();
if (!timingSafeEqual(sig, expected)) return res.status(401).end();
Both are minimal. One is safe to shrink further. One is not. snip tells you which is which.
Install
/plugin install snip
Then use /snip, /snip ultra, or /snip prod in any session.
curl -o .cursor/rules/snip.mdc \
https://raw.githubusercontent.com/amulyavarshney/snip/main/.cursor/rules/snip.mdc
code --install-extension amulyavarshney.snip
Or search "Snip" in the VS Code Extension Marketplace. Adds a status bar badge and Snip: Set Mode command.
curl -o .github/copilot-instructions.md \
https://raw.githubusercontent.com/amulyavarshney/snip/main/.github/copilot-instructions.md
Team config
Commit a .snip.json to your repo. Every developer and CI run
picks it up automatically. One engineer sets the floor, the whole team keeps it.
{
"mode": "full",
"language": "auto",
"prod": { "protect": ["auth", "payments", "billing"] },
"score": { "minScore": 60, "failBelow": true }
}
Add to CI to enforce the score floor on every PR:
# .github/workflows/snip.yml
- run: npx @amulyavarshney/snip score src/ --min-score 60 --fail-below
Language overlays
Snip auto-detects your project language and appends idiomatic shortcuts on top of the base rules.
# snip: lru_cache covers this; upgrade to Redis if cross-process needed
from functools import lru_cache
# snip: dataclass replaces manual __init__ + __repr__ + __eq__
from dataclasses import dataclass
# snip: Counter replaces manual dict accumulation
from collections import Counter
// snip: discriminated union; upgrade to classes if shared methods exceed 3
type Result<T> = { ok: true; value: T } | { ok: false; error: string };
// snip: as const map; upgrade to enum if declaration merging needed
const STATUS = { pending: 'pending', active: 'active' } as const;
// snip: crypto.randomUUID() covers this (Node 19+)
const id = crypto.randomUUID();
// snip: errors.New; upgrade to typed struct if callers need errors.As fields
var (
ErrNotFound = errors.New("user: not found")
ErrForbidden = errors.New("user: permission denied")
)
// snip: fmt.Errorf %w wraps errors; no custom wrapper type needed
return nil, fmt.Errorf("get user %d: %w", id, ErrNotFound)