Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,134 @@
# OpenSpec Change: enterprise-server-linter
- **Change ID**: enterprise-server-linter
- **Package**: `@suaveplan/linter`
- **Category**: server/infra
- **Target path**: `server/infra/linter`
- **Status**: PROPOSED
- **Date**: 2026-04-24
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/linter.md`
---
## Summary
Deliver `@suaveplan/linter` on the genesis branch from scratch at enterprise quality. The package is a shared linting configuration and runtime wrapper for the Suaveplan monorepo. It ships opinionated Biome configuration presets (base, library, react, node, test), a programmatic `LinterRunner` API for running Biome checks in CI pipelines, structured `LintResult` output, and a thin CLI wrapper. No runtime browser deps — this is a Node.js / build-tooling package.
---
## Current-state audit (genesis)
Does not exist on genesis — fresh build.
---
## Available workspace deps on genesis
| Package | Role |
|---|---|
| `@suaveplan/error` (`workspace:^`) | Typed `LINTER.*` error codes |
| `@suaveplan/types` (`workspace:^`) | `LoggerLike` |
| `@suaveplan/logger` (`workspace:^`) | Structured logs |
| `zod` (`catalog:forms`) | Options validation |
| `@opentelemetry/api` (`catalog:observability`) | Counters |
| `@biomejs/biome` (`catalog:build`) | Linter/formatter engine |
| `tslib` (`catalog:build`) | Runtime helpers |
---
## Public API surface
### Programmatic API
```ts
class LinterRunner {
constructor(options?: LinterOptions)
check(targets: string[]): Promise<LintResult>
fix(targets: string[]): Promise<LintResult>
format(targets: string[]): Promise<LintResult>
}
function createLinterRunner(options?: LinterOptions): LinterRunner
interface LinterOptions {
configPath?: string // path to biome.json; default: auto-discover
preset?: 'base' | 'library' | 'react' | 'node' | 'test'
logger?: LoggerLike
}
interface LintResult {
passed: boolean
errorCount: number
warningCount: number
diagnostics: LintDiagnostic[]
duration: number
}
interface LintDiagnostic {
file: string
line: number
column: number
severity: 'error' | 'warning' | 'info'
message: string
rule: string
}
type LinterErrorCode =
| 'LINTER_CONFIG_NOT_FOUND'
| 'LINTER_EXECUTION_FAILED'
| 'LINTER_INVALID_TARGET'
function registerLinterErrorCodes(): void
```
### Config presets (re-exported JSON)
```ts
// Subpath exports for use in biome.json "extends"
// "@suaveplan/linter/presets/base"
// "@suaveplan/linter/presets/library"
// "@suaveplan/linter/presets/react"
// "@suaveplan/linter/presets/node"
// "@suaveplan/linter/presets/test"
```
---
## File layout
```text
server/infra/linter/
package.json
tsconfig.json
vitest.config.ts
presets/
base.json
library.json
react.json
node.json
test.json
src/
index.ts
error-codes.ts
constants/index.ts
types/
linter.types.ts
linter.types.md
runner/
linter-runner/
linter-runner.ts
linter-runner.md
linter-runner.types.ts
linter-runner.test.ts
index.ts
tests/
integration.test.ts
```
---
## Impact
Downstream: every genesis package uses `@suaveplan/linter` presets via `biome.json` extends. The programmatic API is used in CI reporting.
**Prerequisites on Verdaccio**: `@suaveplan/error`, `@suaveplan/types`, `@suaveplan/logger`.

View File

@@ -0,0 +1,72 @@
# Tasks: enterprise-server-linter
**Change ID**: enterprise-server-linter
**Package**: `@suaveplan/linter`
**Target path**: `server/infra/linter`
**Prerequisites on Verdaccio**: `@suaveplan/error`, `@suaveplan/types`, `@suaveplan/logger`
---
## 0. Pre-flight (non-negotiable)
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in each)
- [ ] 0.2 If any worktrees exist under `.claude/worktrees/`, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (`git worktree remove`) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
- [ ] 0.3 Confirm the package set in `MANIFEST.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
## 1. Scaffold
- [ ] Create directory tree per `proposal.md`.
- [ ] `package.json` at `0.1.0`, `"sideEffects": false`, exports:
- `"."`: main barrel
- `"./presets/base"`: `"./presets/base.json"`
- `"./presets/library"`: `"./presets/library.json"`
- `"./presets/react"`: `"./presets/react.json"`
- `"./presets/node"`: `"./presets/node.json"`
- `"./presets/test"`: `"./presets/test.json"`
- `"./runner"`: runner subpath
- [ ] Deps: `@suaveplan/error workspace:^`, `@suaveplan/types workspace:^`, `@suaveplan/logger workspace:^`, `zod catalog:forms`, `@opentelemetry/api catalog:observability`, `@biomejs/biome catalog:build`, `tslib catalog:build`.
- [ ] DevDeps: `vitest catalog:testing`, `@vitest/coverage-istanbul catalog:testing`, `@suaveplan/testing workspace:^`.
- [ ] `tsconfig.json` extending `library-node.json`; `vitest.config.ts` with `createTestConfig()`.
- [ ] Scripts: `lint`, `typecheck`, `test`, `test:coverage`, `build`, `docs:check`.
## 2. Preset JSON files
- [ ] Write `presets/base.json`: Biome config extending Biome recommended; enables linter rules for correctness, complexity, suspicious; format with tabs, double quotes, trailing commas; max line width 120.
- [ ] Write `presets/library.json`: extends base; stricter TypeScript rules (no explicit any, no unsafe member access), required return types.
- [ ] Write `presets/react.json`: extends library; enables JSX rules; allows JSX a11y overrides.
- [ ] Write `presets/node.json`: extends library; allows Node.js `process`, globals.
- [ ] Write `presets/test.json`: extends base; relaxes return-type and explicit-any rules inside test files; allows `describe`/`it`/`expect` globals.
## 3. Types and errors
- [ ] Define `LinterOptions`, `LintResult`, `LintDiagnostic` and Zod schemas in `src/types/linter.types.ts`.
- [ ] Write `linter.types.md` (≥200 words, both examples, API reference).
- [ ] `src/error-codes.ts`: three codes; `registerLinterErrorCodes()`; eager call.
## 4. Linter runner
- [ ] Implement `LinterRunner` in `src/runner/linter-runner/linter-runner.ts`:
- Spawn Biome CLI via `Bun.spawn(['biome', 'check', '--reporter=json', ...targets])` with configPath arg when provided.
- Parse JSON output into `LintResult`. Map Biome diagnostic fields to `LintDiagnostic`.
- `check(targets)`: `biome check` — returns diagnostics without fixing.
- `fix(targets)`: `biome check --apply` — applies safe fixes.
- `format(targets)`: `biome format --write` — formats files.
- Non-zero exit code with no JSON output: throw `LINTER_EXECUTION_FAILED`.
- OTel counter `linter.runs_total` with `command` and `passed`; histogram `linter.duration_ms`.
- [ ] Write `linter-runner.types.ts`.
- [ ] Write `linter-runner.test.ts` (≤500 lines): check passes on valid TS file; check fails on file with intentional error; fix resolves auto-fixable issues; invalid target throws `LINTER_INVALID_TARGET`. Use real temp file with known content.
- [ ] Write `linter-runner.md` (≥200 words, simple + advanced, API reference).
## 5. Integration tests
- [ ] `tests/integration.test.ts`: create a temp TypeScript file with a lint violation; run `check` → expect `passed: false`; run `fix` → expect fixed; run `format` → expect formatted output; `{ timeout: 30000 }`.
## 6. Docs + verify + publish
- [ ] Root `README.md`: preset usage in `biome.json`, programmatic API quick-start, preset comparison table, API table.
- [ ] `bunx turbo lint --filter=@suaveplan/linter` — zero errors.
- [ ] `bunx turbo typecheck --filter=@suaveplan/linter` — zero errors.
- [ ] `bunx turbo test --filter=@suaveplan/linter` — all pass.
- [ ] `bunx turbo test:coverage --filter=@suaveplan/linter` — 100%.
- [ ] `bun scripts/publish.ts --package @suaveplan/linter`.
- [ ] Update `CLAUDE.md`; archive to `openspec/archive/2026-04-24-enterprise-server-linter/`.