AgentSkillsCN

code-quality

为 Schmock 进行代码质量验证。运行测试、检查代码覆盖率、确保合规性。适用于测试、代码审查,或在提交代码前进行准备时使用。

SKILL.md
--- frontmatter
name: code-quality
description: >
  Code quality verification for Schmock. Run tests, check coverage, validate
  compliance. Use when testing, reviewing code, or preparing for commits.
argument-hint: "test all|unit|bdd|<package> | validate | coverage <package>"
allowed-tools:
  - Bash(bash .claude/skills/code-quality/scripts/test.sh *)
  - Bash(bash .claude/skills/code-quality/scripts/validate.sh)
  - Bash(bash .claude/skills/code-quality/scripts/coverage.sh *)

Schmock Code Quality Skill

The Gate: /code-quality validate

The primary command. Runs all 6 quality stages in order and reports pass/fail with fix hints:

#StageWhat it checksAuto-fix?
1LintBiome: formatting, imports, code smellsbun lint:fix
2Typechecktsc --build per packageManual
3KnipDead exports, unused dependenciesManual
4ESLintas type assertions (zero tolerance)Manual
5Unitpackages/*/src/**/*.test.tsManual
6BDDpackages/*/src/steps/*.steps.ts vs features/*.featureManual

All 6 must pass before committing. The pre-commit hook enforces Lint + Typecheck + Unit + BDD automatically.

When a stage fails

Failed stageWhat to do
LintRun bun lint:fix — most issues auto-fix. For remaining: check biome output for the rule name and fix manually.
TypecheckRun bun typecheck for full errors. Usually a missing import, wrong return type, or ambient type mismatch in types/schmock.d.ts.
KnipRun bun knip to see unused exports/deps. Either delete the dead code or, if intentional, add to knip.json ignore.
ESLintRun bun eslint to see as casts. Replace with: toHttpMethod() for HttpMethod, errorMessage() for unknown errors, "prop" in obj narrowing, FakerSchema interface for jsf extensions. Never add as — use satisfies if needed.
UnitRun bun test:unit for full output. Read the failing assertion, fix the source or update the test expectation.
BDDRun bun test:bdd for full output. Common issues: step text doesn't match .feature file exactly, or a new Scenario is missing step definitions. Each step text must be unique within a Scenario.

Zero as policy

The codebase has zero unsafe type assertions. Patterns to avoid as:

Instead ofUse
method as HttpMethodtoHttpMethod(method) — runtime validation
(error as Error).messageerrorMessage(error) helper or instanceof Error guard
(obj as any).fakerFakerSchema interface extending JSONSchema7, or "faker" in obj guard
body as Record<string, unknown>"code" in body && body.code === ... narrowing
error as SchmockErrorRedundant after instanceof SchmockError — just use error.code
value as SomeTypesatisfies SomeType (checks without asserting)

Code smell detection stack

ToolRulesConfig
BiomenoNonNullAssertion, noShadow, noEvolvingTypes, noFloatingPromises, noMisusedPromises, noImportCyclesbiome.json
KnipDead exports, unused dependencies, unlisted depsknip.json
typescript-eslintno-unsafe-type-assertion (error)eslint.config.js

Testing

Commands

CommandDescription
/code-quality validateFull gate — Lint, Typecheck, Knip, ESLint, Unit, BDD
/code-quality test allTypecheck + Unit + BDD (no lint/knip/eslint)
/code-quality test unitUnit tests only
/code-quality test bddBDD tests only
/code-quality test <pkg>Tests for one package: core, schema, express, angular, validation, query
/code-quality coverage <pkg>Per-package coverage report

Test types

TypeLocationConfigPurpose
Unit (.test.ts)packages/*/src/**/*.test.tsvitest.config.tsInternal logic, edge cases
BDD (.steps.ts)packages/*/src/steps/*.steps.tsvitest.config.bdd.tsBehavior contracts vs .feature specs

When to run what

SituationCommand
Quick check during dev/code-quality test unit
Verifying behavior contracts/code-quality test bdd
Before committing/code-quality validate
Single package focus/code-quality test core
After fixing lint/types onlybun lint:quiet && bun typecheck:quiet

Coverage

code
/code-quality coverage core
/code-quality coverage schema
/code-quality coverage validation
/code-quality coverage query

Excludes test files. Focus on source coverage only.

Output Levels

LevelSuffixUse case
Normal(none)Interactive development
Quiet:quietClaude assistant, CI
Silent:silentPre-commit hooks

Quiet variants: bun test:quiet, bun lint:quiet, bun typecheck:quiet, bun knip:quiet, bun eslint:quiet